Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to update SharePoint 2010's managed metadata field with Lists.UpdateListItems web service call

I'm trying to update a SharePoint managed metadata (MMD) field using Lists.UpdateListItems web service but it's not working.

Here is my SOAP request

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
  <UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <listName>My Test List</listName>
    <updates>
      <Batch ListVersion="0" PreCalc="TRUE" OnError="Continue">
        <Method Cmd="Update" ID="1">
          <Field Name="ID">3</Field>
          <Field Name="Document_x0020_Title">foo</Field>
          <Field Name="Fiscal_x0020_Year1">13;#FY 2006|7e8205da-57a1-45a3-8147-469b795ad6e8</Field>
        </Method>
      </Batch>
    </updates>
   </UpdateListItems>
</S:Body></S:Envelope>

This request will succesfully update the "Document Title" (a text field) but the MMD field, "Fiscal Year", was unchanged and there is no error returned from the web service.

Note that the value of the MMD is in the format "WssId;#TermValue|TermGuid" and the term has already been created for the site.

Please help.

like image 397
duvo Avatar asked Jul 09 '12 17:07

duvo


2 Answers

Figured it out.

I must use a different field name. The label for the field is "Fiscal Year", but the field name that worked is actually "d3c0ddc947ab4b8c90b6a0fe2d4caf09" instead of "Fiscal_x0020_Year1". So my SOAP request would look like

    <Method Cmd="Update" ID="1">
      <Field Name="ID">3</Field>
      <Field Name="Document_x0020_Title">foo</Field>
      <Field Name="d3c0ddc947ab4b8c90b6a0fe2d4caf09">13;#FY 2006|7e8205da-57a1-45a3-8147-469b795ad6e8</Field>
    </Method>

To get this field name I use the Lists.GetListContentType web service method to return fields information and look for fieldtype "Note". Here is an example of what SharePoint returned

<Field Type="Note" DisplayName="Fiscal Year_0"
StaticName="d3c0ddc947ab4b8c90b6a0fe2d4caf09" Name="d3c0ddc947ab4b8c90b6a0fe2d4caf09" 
ID="{1afa458b-d50a-4139-ad8d-f1172774de34}" ShowInViewForms="FALSE" Required="FALSE" 
CanToggleHidden="TRUE" SourceID="{77871b4e-f3ba-42dc-8940-ab33fb431099}" Hidden="TRUE" 
Version="1" Customization="" ColName="ntext8" RowOrdinal="0"/>

I also find it useful to use the Lists.GetListContentTypes method to get the content type id use in Lists.GetListContentType method call.

----Update-- I found that you don't have to use the format of "WssId;#TermValue|TermGuid". You can simply use "TermValue|TermGuid". So in the example above the value would be "FY 2006|7e8205da-57a1-45a3-8147-469b795ad6e8".

This is very useful because you can reuse the same value across different site unlike the former value, where you can only use it in one site. For multi value you only need to delimit it with a ";" instead of ";#". For example "FY 2006|7e8205da-57a1-45a3-8147-469b795ad6e8;FY 2007|823205da-57a1-45a3-8147-469b795ade13".

like image 96
duvo Avatar answered Oct 19 '22 07:10

duvo


Thanks for mentioning the bit about StaticName. That put an end to my suffering.

It would seem that for simple fields, not linked to MMS, like Title, a lazier update syntax is permitted. For example, on it's own, the following update is processed without an error.

<Field Name="Title">Some Title</Field>

However, the rules are not the same for fields linked to MMS.
Following the approach above, I moved into my MMS fields. That type of field can be updated with arbitrary values if you identify it by it's friendly name and input an integer, e.g.:

<Field Name="Activity">20</Field>

The "20" just translates to some term.
I tried many numbers and they all came back as the same term.

Alternatively, If I move closer to the documented way of updating the value, while still identifying the field with "Activity", the service returns an error 0x80020005.

<Field Name="Activity">HTA|fe951639-7c90-41ee-9888-6ae0e6523120</Field>

So don't do that.
Only when the moons are fully aligned do I find success. The StaticName is key.

<Field Name="j06a8d8240f84aec987f6a28effa3ae1">HTA|fe951639-7c90-41ee-9888-6ae0e6523120</Field>

Another way to find the StaticName is to look for the Field Type="Note" for each MMS Field in the response to a GetList request. This operation takes 1 less input than GetListContentType. You only need the list name and not a contentTypeID.

Rock on.

like image 31
catBus Avatar answered Oct 19 '22 05:10

catBus