Un po' di codice già pronto da utilizzare in tutti gli addins Sharepoint-hosted che debbano accedere all'host web.
// Function to retrieve a query string value.
// For production purposes you may want to use
// a library to handle the query string.
function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve)
return singleParam[1];
}
}
var clientContext = SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
$.getScript("../_layouts/15/SP.RequestExecutor.js", initializePart);
function initializePart() {
var factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
clientContext.set_webRequestExecutorFactory(factory);
var appContextSite = new SP.AppContextSite(clientContext, hostweburl);
workWeb = appContextSite.get_web();
clientContext.load(workWeb);
clientContext.executeQueryAsync(ongetWebSuccess, ongetWebFail);
}
Nessun commento:
Posta un commento