0

I am trying to emulate a sharepoint new form in a custom react app of multiple pages. My problem is how will I store the data that user enters across multiple pages and save it in the sharepoint list. Please let me know.

2
  • How's it hosted? How are you handling authentication? Commented Jun 7, 2018 at 16:12
  • I am planning to host it as a provider hosted app
    – karthik
    Commented Jun 8, 2018 at 5:23

1 Answer 1

0

If your react app is hosted on sharepoint, you can use the rest interface:

function createListItem(siteUrl, listName, itemProperties, success, failure) {
    var itemType = listName + 'ListItem'; //may need additional substitution for some characters in listName
    itemProperties.__metadata = {
        "type": itemType
    };
    $.ajax({
        url: siteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(itemProperties),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            success(data.d);
        },
        error: function (data) {
            failure(data);
        }
    });
}

You would call it like this (SPO example): createListItem('https://mycompany.sharepoint.com', 'MyList', { 'Title': 'MyNewListItem', 'MyAttribute': true }, successhandler, errorhandler)

Notice the X-RequestDigest in the header. That is only available on SP-Sites, where you are authenticated. You need write permissions for the list of course and operations are performed with that particular user.

If you are hosted elsewhere, you need to get an auth token first.

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.