locked
How to Add&Update the value of manage metadata field in Silverlight using sharepoint client object model ?? RRS feed

  • Question

  • How to Add&Update the value of manage metadata field in Silverlight using sharepoint client object model ??

    This is my code :

    ClientContext clientContext = ClientContext.Current;
                    Web oWebsite = clientContext.Web;
                    ListCollection collList = oWebsite.Lists;
                    ListItem oListItem;

                    List oList = clientContext.Web.Lists.GetByTitle("Employees");

                    oListItem = oList.AddItem(new ListItemCreationInformation());
                    oListItem["Title"] = "My new item";

    oListItem["Geography"] = "Kroea";//This is MetaData Field

    oListItem.Update();

     

    the oListItem["Geography"] = "Kroea" must be formatted like oListItem["Geography"] = "2;#Kroea",that code will be worked.

    The "2;#Kroea "  was found form the list throught caml query tools.But I can't get the id(like "2") from matedata service  through client object mode or Soap Service,I just can get term GUID and Name.

    How should I add&upate this type filed value ??

     

    • Moved by Lily Wu Friday, September 24, 2010 9:13 AM (From:SharePoint 2010 - General Questions and Answers)
    Sunday, September 19, 2010 12:53 PM

Answers

  • Hi Tony,

     

    Yes, you are correct in that the format for directly updating a taxonomy field (managed metadata field) in a list is to provide the value in this format: [WssId];#[Term]|[TermGuid].  To answer your question, the first part ([WssId]) can be obtained from a hidden list at the root of the site collection called the “TaxonomyHiddenList”.  You can browse to it by: http://sharepointurl/Lists/TaxonomyHiddenList.  The “ID” field (after you enable it in the default view of this list) is the WssId that you can use.

     

    However, there’s a point you have to be aware of.  The WssId values are available only for terms you have already used.  If you have a fresh term (i.e., a term defined in the managed metadata service app, but not used in the site collection), you will not be able to find that term in this hidden list.  Because of that you will not be able to add this new term as a value for a taxonomy field in your lists.  Using server object model, we can use the TaxonomyField object to set this value.  But since client object model only support WSS 4.0 objects, we don’t have TaxonomyField class available.

     

    Let me check further on how we can add new taxonomy field values to a taxonomy field in a list in a reliable way.  We’ll update you once we have more information on this.


    AnjaliCH-MSFT
    • Marked as answer by Lily Wu Thursday, October 7, 2010 2:32 AM
    Wednesday, September 29, 2010 12:54 PM
  • Hi Tony,

    Unfortunately, you will not be able to work with taxonomy fields with any of the client object models.  You have to use server object model to achieve this.

    Thanks,


    Sridhar Raghunathan - MSFT
    Tuesday, October 19, 2010 6:25 AM

All replies

  • Hi Tony,

     

    Yes, you are correct in that the format for directly updating a taxonomy field (managed metadata field) in a list is to provide the value in this format: [WssId];#[Term]|[TermGuid].  To answer your question, the first part ([WssId]) can be obtained from a hidden list at the root of the site collection called the “TaxonomyHiddenList”.  You can browse to it by: http://sharepointurl/Lists/TaxonomyHiddenList.  The “ID” field (after you enable it in the default view of this list) is the WssId that you can use.

     

    However, there’s a point you have to be aware of.  The WssId values are available only for terms you have already used.  If you have a fresh term (i.e., a term defined in the managed metadata service app, but not used in the site collection), you will not be able to find that term in this hidden list.  Because of that you will not be able to add this new term as a value for a taxonomy field in your lists.  Using server object model, we can use the TaxonomyField object to set this value.  But since client object model only support WSS 4.0 objects, we don’t have TaxonomyField class available.

     

    Let me check further on how we can add new taxonomy field values to a taxonomy field in a list in a reliable way.  We’ll update you once we have more information on this.


    AnjaliCH-MSFT
    • Marked as answer by Lily Wu Thursday, October 7, 2010 2:32 AM
    Wednesday, September 29, 2010 12:54 PM
  • Hi Tony,

    Unfortunately, you will not be able to work with taxonomy fields with any of the client object models.  You have to use server object model to achieve this.

    Thanks,


    Sridhar Raghunathan - MSFT
    Tuesday, October 19, 2010 6:25 AM
  • Hi AnjaliCH,

    Is there any update on this issue?  In order to write Taxonomy fields from client object model, does the field need to exist first in TaxonomyHiddenList?  This is a hindrance for those migrating data to SharePoint. 

    Thanks.

     

    Thursday, December 16, 2010 2:21 PM
  • So I believe that the above information isn't totally accurate.

    You should be able to set the corresponding hidden text field of the taxonomy field as follows:

    <label1>|<guid1>;…;<labelN>|<guidN>

    and that should find the correct hidden item value / create it if necessary / etc.  I don't currently have a machine to test this on, but this should work. (Sorry for not being more precise).

    Take a look at the values in the hidden text field paired to the taxonomy field for an exact example.

    Pat.

    Friday, April 1, 2011 5:18 PM
  • As Pat stated, you can set it using that format, but to the text field of your taxonomy field. You are probably aware of this already; taxonomy fields have a hidden "helper" note field. The correct naming convention is Taxonomy Field Static Name + TaxHDField0. So lets say your taxonomy field has a static name of "Test", the helper field will be called "TestTaxHDField0". Simply push the value as Pat specified above and you are set.

     


    <Lambros />
    Wednesday, June 8, 2011 8:05 PM
  • See my example + code examples here.
    Tuesday, August 21, 2012 9:10 AM