Tuesday 2 June 2015

Create a sharepoin list in the host web for SharePoint hosted app by means of REST Call


It is possible to create a list in the host web by means of REST call from the app web for SharePoint hosted app. The following code snippets illustrates the scenario:



function createList(listName, onCreated, onError) {

    var executor;
    executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web/Lists?@target='" + hostweburl + "'",
        method: "POST",
        body: "{ '__metadata': { 'type': 'SP.List' }, 'Hidden':true,  'AllowContentTypes': true,'BaseTemplate': 100,'Description': '" + listName + "', 'Title':'" + listName + "'}",
        headers: {
            "content-type": "application/json; odata=verbose", "Accept": "application/json;odata=verbose"
        },
        success: onCreated,
        error: onError
    });


}

Test it in your own environment.



Happy SharePointing....:)

No comments:

Post a Comment