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.

4
  • 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. Commented Aug 8, 2015 at 15:53
  • Yes,I want to update the created item with the above value.How to achieve this requirement through JS code. Commented Aug 9, 2015 at 6:16
  • May be the current item getting saved before the value got populated into field. Createlistitemthroughrestapi, is it synchronous? Commented Aug 9, 2015 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. Commented Aug 9, 2015 at 10:09

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.