We would like to call the SXA clone website script on custom button click.

Is it possible to call SXA clone functionality on button click by javascript or C# code?

  • Where would you like to have that button? Aug 23, 2019 at 10:45
  • We would like to create separate tool which will further link to automated content update using content matrix. This can on custom page inside CMS. Aug 23, 2019 at 11:38

1 Answer 1


You will need to call the SXA Clone Script using the code snippet below

using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default", true))
    var siteItem = Factory.GetDatabase("master").GetItem("path to site or site item id");

    var scriptItem = Sitecore.Context.Database.GetItem("/sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Multisite/Content Editor/Context Menu/Clone Site");

    var script = scriptItem["Script"];

    if (!string.IsNullOrEmpty(script))

The SXA Clone Script retrieves the context item using Get-Item ., so you will need to pass the site item you want to clone to the script. This is what the code scriptSession.SetItemLocationContext(siteItem); does. Upon clicking on the button, the above code is called.

If you are expecting a return value from the powershell script, the you will need to pass false as second parameter in the ExecuteScriptPart method.

scriptSession.ExecuteScriptPart(script, false);

Now, if you want to call the SXA Clone Script via javascript, you will need to call the URL of the powershell runner. The powershell runner will allow the popup of the clone dialog to open.

var shellSite = SiteContext.GetSite("shell");

using (new SiteContextSwitcher(shellSite))
    var urlString = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));
    urlString.Append("id", siteId);
    urlString.Append("db", "master");
    urlString.Append("scriptId", "SXA CLONE SCRIPT ITEM ID");
    urlString.Append("scriptDb", "master");

    return new JsonResult { Data = urlString.ToString(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };

Note: I haven't yet tested the code but this is the way to go. More information is available at my blog post on Sitecore Powershell with SPEAK UI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.