1

I have a sharepoint online list which I am updating via javascript in the same sharepoint site. The list has two similarly named columns: Display name: "Learner Score" Internal name:"LearnerScore" Display name: "Learner Score %" Internal name:"LearnerScorePercent"

I am updating the fields via a REST merge, and when I specify the data value, I have to use "LearnerScore" for the "LearnerScore" field and "LearnerScore0" for the "LearnerScorePercent" field.

I have found that this method of specifying the field is ambiguous - if I add a third column with display name "Learner Score%"(no space) and internal name "LearnerScoreTest" - I must specify field name of "LearnerScore1" in my REST data.

This is causing some confusion for me in the code, plus the code must be changed if we change the display name.

Is it possible to specify the Internal name of the field in the data parameter?

my update function:

UpdateEntry(1,"{'Learner0':'40'}");
function UpdateEntry(itemId,itemData){        
    var url="https://company.sharepoint.com/sites/johntest/_vti_bin/listdata.svc/RestTest("+itemId+")";    
    $.ajax({
        type: 'POST',
        url: url,
        contentType: 'application/json',
        processData: false,        
        data:itemData,
        headers:{
            "Accept":"application/json;odata=verbose",
            "X-RequestDigest":$("#__REQUESTDIGEST").val(),
            "X-HTTP-Method":"MERGE",
            "If-Match":"*"
        },
        success: function (data) {
            alert('success'); 
        },
        error: function(data){
            alert('error');
        }
    });
}
0

Your itemdata needs to include the metadata of the list type. Your code should work something similar to below. (Please note I've written this without testing in my environment. Also, I'm not sure what column type your Learner0 field is. If it's a person field, you would find a internal column called LearnerId and it is this column to update with the number.)

Update person or group field using REST API in Document Library

var metatdata = @"{
  __metadata:{ type: 'SP.Data.RestTestItem' },
  Title:'My New Title',
  Learner0:'40'
}";

UpdateEntry(1, JSON.stringify(metadata));

function UpdateEntry(itemId,itemData){        
    var url= _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('RestTest')/items(" + itemID + ")";
    $.ajax({
        type: 'POST',
        url: url,
        contentType: 'application/json',
        processData: false,        
        data: itemData,
        headers:{
            "Accept":"application/json;odata=verbose",
            "X-RequestDigest":$("#__REQUESTDIGEST").val(),
            "X-HTTP-Method":"MERGE",
            "If-Match":"*"
        },
        success: function (data) {
            alert('success'); 
        },
        error: function(data){
            alert('error');
        }
    });
}

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.