Created
February 13, 2018 01:04
-
-
Save tmurvv/a42a95b2ab8efb868cf5d508ed4a166d to your computer and use it in GitHub Desktop.
Case Study Site Creation "Request uses too many resources."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outerObject = outerObject || {}; | |
SP.SOD.executeFunc("sp.js"); | |
//These functions taken from the internet | |
function getUrlVars() { | |
var vars = [], hash; | |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | |
for (var i = 0; i < hashes.length; i++) { | |
hash = hashes[i].split('='); | |
vars.push(hash[0]); | |
vars[hash[0]] = hash[1]; | |
} | |
return vars; | |
}; | |
function getUrlVar(name) { | |
return getUrlVars()[name]; | |
}; | |
var hostWebUrl = decodeURIComponent(getUrlVar('SPHostUrl')); | |
var appWebUrl = decodeURIComponent(getUrlVar('SPAppWebUrl')); | |
jQuery.getScript( | |
hostWebUrl + "/_layouts/15/SP.RequestExecutor.js", | |
continueExecution | |
); | |
function continueExecution() { | |
//Begin Create Site Portion | |
outerObject.CreateSite = outerObject.CreateSite || | |
function CreateSite(event) { | |
SP.SOD.executeFunc("sp.js"); | |
// Get App and Host context (don't be confused that the object name has the word 'app' in it) | |
var appContext = SP.ClientContext.get_current(); | |
var hostContext = new SP.AppContextSite(appContext, hostWebUrl); | |
// Create variables, object, and properties for sub-site | |
//debugger; | |
var userSiteName = $("#userInputSiteName").val(); | |
var userSiteCode = $("#userInputSiteCode").val(); | |
var newSiteDetails = new SP.WebCreationInformation(); | |
newSiteDetails.set_title(userSiteName); | |
newSiteDetails.set_url(userSiteCode); | |
newSiteDetails.set_language(1033); | |
newSiteDetails.set_webTemplate("CASESTUDYMONMORN#0"); | |
// Create the Site URL | |
var siteUrl = String.format(hostWebUrl + "/" + userSiteCode); | |
// Get the web site and site Collection from host site and add sub-site | |
var website = hostContext.get_web(); | |
var webCollection = website.get_webs(); | |
webCollection.add(newSiteDetails); | |
// execute query | |
$("#messageToUser").text("Working on it..."); | |
$("#messageToUserArea").css("color", "black"); | |
$("#messageToUserArea").css("display", "block"); | |
appContext.set_requestTimeout(10*60*100000); | |
appContext.executeQueryAsync(successSubsiteCreation, failSubsiteCreation); | |
function successSubsiteCreation(sender, args) { | |
$("#messageToUser").html("Success creating project site '" + userSiteName + "' at <a href='" + siteUrl + "'>" + siteUrl + "</a>."); | |
$("#messageToUserArea").css("color","green"); | |
$("#messageToUserArea").css("display", "block"); | |
} | |
function failSubsiteCreation(sender, args) { | |
$("#messageToUser").text("Error occurred while attempting to create site " + userSiteName + " at URL " + siteUrl + ". \n" + args.get_message() + "\n" + args.get_stackTrace() + "\n" + args.get_errorDetails()); | |
$("#messageToUserArea").css("color", "red"); | |
$("#messageToUserArea").css("display", "block"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment