0

I am creating a rest api based tool that will migrate items from one list to another with versions. I am successfully able to do the same by reading the version data of source item and updating the item at the destination to create versions. All of this is done using simple rest calls. only issue is that editor and author fields are not getting updated. even though in the post body i am sending the correct editor and author value. Is it possible to update these two columns just by using rest api calls. if yes how?

1 Answer 1

0

You need to update the Created By and Modified By field to not be read only. You can post to: /_api/web/lists/getByTitle('myList')/Fields/getByTitle('Created By'), update the field ReadOnlyField to false.

After that the updates to AuthorId will work.

$.ajax
    ({            
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('myList')/fields/getbytitle('Created By')",
        method: "POST",
        data: JSON.stringify({
            '__metadata': {                    
                'type': 'SP.FieldUser'
            },
            'ReadOnlyField': false
        }),
        headers:
           {
              "IF-MATCH": "*",
               "X-HTTP-Method": "PATCH",
               "Accept": "application/json;odata=verbose",                   
               "Content-Type": "application/json;odata=verbose",                  
               "X-RequestDigest": $("#__REQUESTDIGEST").val()
           },
        success: function (data, status, xhr) {
            console.log("Success");
        },
        error: function (xhr, status, error) {
            console.log("Failed");
        }
    });

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.