2

I have been creating a load of site columns with powershell from a .csv file. I am now trying to create new taxonomy or metadata field:

               $spField = $web.Fields.CreateNewField($fieldType, $siteColumn.DisplayName)
                    # updat properties related ot MMS
                    # Update the properties of the new field.
                    $spField.SspId = $termSet.TermStore.ID
                    $spField.TermSetId = $termSet.Id 
                    $spField.AnchorId = $termID

but I also want to set a default value (not just the anchor for a range of terms)

  $defaultTerm = $terms | Where-Object {$_.Name -eq $siteColumn.Default}

Now I am stuck because I need update $spField.DefaultValue with a format it accepts e.g.

 45;#Customer Document|60d5d501-3d38-4842-80f0-c897a12b7e34

How can I do this from a .csv file?

0

For each field you should identify the default term name. Then to get the Unique ID, you need to iterate through the term store as below

$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) 
$termStore = $session.TermStores[0] 
$group = $termStore.Groups["GroupName"] 
$termSet = $group.TermSets["TermsetName"] 
$terms = $termSet.GetAllTerms() 
$term = $terms | ?{$_.Name –eq "TermName"}

Once you have the $term, you can form the default value as

"45;#" + $term.Name + "|" + $term.Id
  • 2
    Please use -1instead of 45though, since we do not know the lookup id – Robert Lindgren Nov 4 '14 at 11:35
  • Thanks for the reply. Ok, I see you have located the (default) term and you have formatted a string with its properties. But how did you get the "nn;#" part.. I know that is the internal format it is just not easier to see how it is stored – westerdaled Nov 4 '14 at 11:54
  • The lookup id (called WssId "officially") is a sitecollection-specific value. You can read more about that and find C# code samples how to get / create that in these posts: pholpar.wordpress.com/2010/02/03/… pholpar.wordpress.com/2010/12/23/… – pholpar Nov 4 '14 at 12:06
  • I understand. I little inconsistent of sharepoint ( not using a guid) but I see that as I am creating my site column in a Site collection it makes sense. Ok will test this out in the office tomorrow thanks also @Amal – westerdaled Nov 4 '14 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.