spscript icon indicating copy to clipboard operation
spscript copied to clipboard

Add SiteDesign and SiteScript utilities

Open DroopyTersen opened this issue 5 years ago • 0 comments

Where would they go on the SPScript global?

async function getSiteDesign(siteUrl, siteDesignName) {
    const ctx = SPScript.createContext(siteUrl);
    // GetSiteDesigns actually requires a POST
    let data = await ctx.authorizedPost(
        "/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteDesigns"
    );
    let siteDesigns = data.d.GetSiteDesigns.results;
    return siteDesigns.find(sd => sd.Title === siteDesignName);
}

async function applySiteDesign(siteUrl, siteDesignName) {
    // Take the name and try to find a Site Design with that Title
    let siteDesign = await getSiteDesign(siteUrl, siteDesignName);
    if (!siteDesign) throw new Error("Couldn't find a site design with the name, " + siteDesignName);
    let ctx = SPScript.createContext(siteUrl);

    let endpoint = "/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ApplySiteDesign";
    let payload = { siteDesignId: siteDesign.Id, webUrl: siteUrl };
    await ctx.authorizedPost(endpoint, payload);
}

DroopyTersen avatar Mar 19 '19 00:03 DroopyTersen