1

I am using REST API to create a list item in another list. Based on the successful creation of the list item I am just updating the current SharePoint field value. This whole process is executing through PreSaveAction() method.

Here I am able to pre fill list column, but after saving the list item the pre fill column is empty.

Here is my Code:

function PreSaveAction()
{
    createListItemThroughRESTAPI();
    $('input[id*="<'id Name'>"]').attr('value','Test Value');
    return true;
}

Any help would be greatly appreciated.

  • 1
    Do you want to update the created item with test value? Then you need to get the item and set value to that item. Your JS code will not update the list item. – Akhoy Aug 8 '15 at 15:53
  • Yes,I want to update the created item with the above value.How to achieve this requirement through JS code. – user44932 Aug 9 '15 at 6:16
  • May be the current item getting saved before the value got populated into field. Createlistitemthroughrestapi, is it synchronous? – sekhar Aug 9 '15 at 10:02
  • Yes,I am able to populate the value into the field through Createlistitemthroughrestapi(Custom Method which is used to create item on another list).But after the item saved into the list,the populated value is missing.But this is not happening to default title field. – user44932 Aug 9 '15 at 10:09
0

To create List item using Rest call, you need to do the following:

1) Set the metadata properties as-

var item = {
        "__metadata": { "type": itemType },
        "Title": newItemTitle
    };

2) Ajax call:

$.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });

Source Reference : https://tjendarta.wordpress.com/2014/02/20/create-retrieve-update-and-delete-sharepoint-list-item-using-rest-api-and-jquery/

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.