Home > PowerShell, SharePoint, SharePoint 2010 > SharePoint 2010: How to set Taxonomy Field Values programmatically
  1. devendra singh
    July 4, 2012 at 13:04

    Hi,

    I am creating custom UserProifle edit page, for all taxonomy type property generating taxonomy control on edit profile page using TaxonomyWebTaggigControl. When page is rendering it works fine but it is not setting the value for SPS_Location and SPS-Past projects user properties, other taxonomy type properties like Skills,school,interesets etc are rendering properly. Can anyone please help me hereto find out what is the reason why it is not setting value in SPS-Location filed. There is no server side error/exception found.
    Please reply ASAP

    Devendra

    • July 6, 2012 at 19:39

      Hi Devendra

      I believe those fields you mentioned are not taxonomy fields even though they look a bit like them so the TaxonomyWebTaggingControl will not work with them.

      Best regards

      Nick

  2. Bastiaan
    July 20, 2012 at 15:29

    Thanks for your blog! I had an event receiver that updated a hidden managed metadata field programmatically, the wrong way. I was really bumping my head against the wall to figure out why this error appeared in our crawl log. After using the SetFieldValue method, things started working smoothly again. Unfortunitelly I had to SystemUpdate all existing documents to kick off my improved EventReceiver. Thank God for PowerShell!

  3. jpouliezos
    April 9, 2013 at 01:13

    Thanx for your post. This is just one more of this SharePoint things, isn’t it? I just want to ask you for a clarification, considering your March 5th update: Does that mean that using this overload of the SetFieldValue method will properly update the Taxonomy field, or we still need to use your awesome powershell scripts ?

    • April 10, 2013 at 05:41

      The SetFieldValue static method is all that you need to use.

  4. June 7, 2013 at 02:57

    I am working on a document Upload service, which will upload the file to a Drop off library, then routed by the routing rules. But we identify that Routing rules will not be triggered on programmatically uploaded documents.

    So, we are Using OfficialFileCore class in Microsoft.Office.Policy for this task.

    OfficialFileCore.SubmitFile() method will upload and automatically trigger the routing rule.

    Everything is working as expected. But, now using Managed Metadata in one of the fields brought a new issue.

    We will be creating RecordsRepositoryProerty object for each of the mandatory fields as below and will add it while file submission.

    Adding properties:

    properties.Add(new RecordsRepositoryProperty { Name = “Name”, Type = “Text”, Value = file.FileName + “test” });

    Submit method:

    var result = OfficialFileCore.SubmitFile(
    objWeb,
    ReadByteArrayFromStream(file.FileContent),
    properties.ToArray(),
    file.ContentTypeName,
    file.FileName,
    farmadminAccount,
    false,
    out destination,
    out customOutput);

    Everything working great for all the fields except Metadata field.

    properties.Add( new RecordsRepositoryProperty
    {
    Name = “SupportingDocumentType”,
    Type = “TaxonomyFieldType”,
    Value = requiredTerm.Id.ToString()
    });

    properties.Add( new RecordsRepositoryProperty
    {
    Name = “SupportingDocumentType_0”,
    Type = “TaxonomyFieldType”,
    Value = requiredTerm.Id.ToString()
    });

    First one is field and second one is Note(hidden field), requiredTerm.Id gives GUID of term.
    The “Type” value is creating issue. I have used everything like “TaxanomyField”, “TaxanomyFieldValue”, “TaxanomyFieldType”. “Microsoft.Sharepoint.Taxonomy.TaxonomyField”, “Microsoft.Sharepoint.Taxonomy.TaxonomyFieldValue”, “Text” and “Guid”. We are unable to find the exact string assigned to Type, which will make framework to identify the GUID as a Taxonomy field and display the pertaining Term.

    • June 13, 2013 at 22:07

      Hi Pratap

      Unfortunately when setting values for taxonomy fields, it is not as simple as just adding the GUID of the term in the fields.

      The Taxonomy Field should contain a value with the format “{0};#{1}” where {0} is the WSS ID (not a GUID but the ID of the term found in the TaxonomyHiddenList), and {1} is the term name.

      The hidden text field value uses the format “{0}|{1}” where {0} is the term name, and {1} is the term GUID. This format is known as a Label Guid Pair and uses a Pipe (|) delimiter.

      Both fields must be populated with the formats described above before they will work.

      I have not tried this specifically with the Official File upload web service but expect it to use the same field formats as everywhere else.

      Hope this helps

      Nick

  5. benjamin
    December 4, 2013 at 08:05

    thanks for the article/code.
    any idea, how to add a manged metada column from a rmeote system ?
    if i use copy.asmx , it didnt work. any other approaches ? ther eis no field property enumeration for the copy.asmx
    am stuck with this reqmnt, as i am passing few paramters including the termset name from other system

    pls help
    thnx benjamin

  6. September 18, 2014 at 11:48

    Thanks for the great article. I was struggling with the exception ” GUID does not exist in the term store” when trying to SetFieldValue for taxonomy field and tis solved by setting taxonomy field Id and value.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: