Sunday, 31 May 2015

Check If a list exist in host web from app web by means of REST call for provider hosted app



We can check whether a list exists in host web for the app web. This can be done by REST call to the Host web from App Web. The below code samples illustrates the scenario:



function isListExist(listName, onExist, onNotExist) {
    var executor;
    executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web/Lists/getbytitle('" + listName + "')?                   @target='" + hostweburl + "'",
        method: "GET",
        headers: {
            "content-type": "application/json; odata=verbose", "Accept": "application/json;odata=verbose"
        },
        success: onExist,
        error: onNotExist
    });
}

No comments:

Post a Comment