1

I am trying to use JQuery and the listData.svc to update a list that has a choice column.

I am using Postman to generate my http requests, can someone please show me examples of how to update choice columns person group columns using listData.svc.

My list is a simple list. Has three columns two have string values the one is a choice between two values Offsite or Onsite. I want to change a column with the value of Offsite to Onsite. I would also like to see an example of how to add/update a value to a person/group column using listData.svc. I have been searching the web but have had much difficulty finding any solid examples for these fields.

0

When working with User fields via REST API in SharePoint 2010 (listData.svc) you need to specify UserId in Update operation.

For example, in Tasks list the column AssignedTo in REST would be referenced as AssignedToId

How to update list item using REST API in SharePoint 2010

function updateListItem(webUrl,listName,itemId,itemProperties,success, failure)
{
   getListItemById(webUrl,listName,itemId,function(item){

      $.ajax({
         type: 'POST',
         url: item.__metadata.uri,
         contentType: 'application/json',
         processData: false,
         headers: {
                "Accept": "application/json;odata=verbose",
                "X-HTTP-Method": "MERGE",
                "If-Match": item.__metadata.etag
         },
         data: Sys.Serialization.JavaScriptSerializer.serialize(itemProperties),
         success: function (data) {
                success(data);
         },
         error: function (data) {
                failure(data);
         }
      });

   },
   function(error){
       failure(error);
   });


}



function getListItemById(webUrl,listName, itemId, success, failure) {
    var url = webUrl + "/_vti_bin/listdata.svc/" + listName + "(" + itemId + ")";
    $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d);
        },
        error: function (data) {
            failure(data.responseJSON.error);
        }
    });
}

Example

How to set AssignedTo field via REST API in SharePoint 2010

var taskProperties = {
    'TaskName': 'Approval',
    'AssignedToId': 12
};

updateListItem('https://contoso.sharepoint.com/project/','Tasks',2,taskProperties,function(item){
    console.log('Task has been updated'); 
  },
  function(error){
    console.log(error);
  }
);

References

Using the REST Interface

  • I'm glad it helped ;) – Vadim Gremyachev Mar 21 '14 at 20:42
  • Im receiving this error: Error processing request stream. The property name 'TaskName' specified for type 'Microsoft.SharePoint.DataService.TasksItem' is not valid. Any thoughts? – user25819 May 13 '14 at 20:07

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.