1

I am trying to create one new list item in Sharepoint 2010 using REST.

Coding

var itemProperties = {
'Title': ;Raja;, //Single line String
'Expiry_x0020‌​_Date': "02/02/2016", //Date
'Permission_x0020‌​_Type': 'Add' //Choice Column
};

createListItemREST('http://xyz:5000/sites/n/', 'L2', itemProperties, function(task){ 
console.log('Task' + task.TaskName + ' has been created');}, function(error){ console.log(JSON.stringify(error)); });

function createListItemREST(webUrl,listName, itemProperties, success, failure) {
    $.ajax({
        url: webUrl + "/_vti_bin/listdata.svc/" + listName,
        type: "POST",
        processData: false,
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(itemProperties),
        headers: {
            "Accept": "application/json;odata=verbose"
        },
        success: function (data) {
            success(data.d);
        },
        error: function (data) {
            failure(data.responseJSON.error);
        }
    });
}

i am getting following error.

400 Bad request

{"code":"","message":{"lang":"en-US","value":"Error processing request stream. The property name 'Expiry_x0020‌​_Date' specified for type 'Microsoft.SharePoint.DataService.L2Item' is not valid."}}

Note: When trying with only Title column this coding is working.

Column Details

Title - Single Line Text

Business Justification for Access - Choice Column

Expiry Date - Date and Time

Permission Type - Choice Column

 <ViewFields xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <FieldRef Name="Attachments" />
      <FieldRef Name="LinkTitle" />
      <FieldRef Name="Business_x0020_Justification_x00" />
      <FieldRef Name="Expiry_x0020_Date" />
      <FieldRef Name="Permission_x0020_Type" />
 </ViewFields>

1 Answer 1

1

I got solution to my question.

After Updating the itemProperties i had get resolved of my issue.

Updated Code.

var itemProperties = {
'Title': userAccName,
'BusinessJustificationForAccessValue': busJust,
'ExpiryDate': expDate,
'PermissionTypeValue': 'Add'
};

When i browse my list with REST URL(http://xyz:5000/sites/n/_vti_bin/listdata.svc/L2) in browser i got above column names change in REST result see below.

 <content type="application/xml">
  <m:properties>
    <d:ContentTypeID>0x010093251D5BCE625C418182AA4A1133397B</d:ContentTypeID>
    <d:Title>Test</d:Title>
    <d:BusinessJustificationForAccessValue>Audit</d:BusinessJustificationForAccessValue>
    <d:ExpiryDate m:type="Edm.DateTime">2016-02-10T00:00:00</d:ExpiryDate>
    <d:PermissionTypeValue>Add</d:PermissionTypeValue>
    <d:Id m:type="Edm.Int32">30</d:Id>
    <d:ContentType>Item</d:ContentType>
    <d:Modified m:type="Edm.DateTime">2016-02-02T06:26:37</d:Modified>
    <d:Created m:type="Edm.DateTime">2016-02-02T06:26:37</d:Created>
    <d:CreatedById m:type="Edm.Int32">1</d:CreatedById>
    <d:ModifiedById m:type="Edm.Int32">1</d:ModifiedById>
    <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
    <d:Version>1.0</d:Version>
    <d:Path>/sites/raja/Lists/L2</d:Path>
  </m:properties>
</content>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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