Skip to content

Instantly share code, notes, and snippets.

@wictorwilen
Created July 15, 2015 12:56
Show Gist options
  • Save wictorwilen/b994571771e5ed0fbc29 to your computer and use it in GitHub Desktop.
Save wictorwilen/b994571771e5ed0fbc29 to your computer and use it in GitHub Desktop.
Add Custom Action using JSOM
var context = SP.ClientContext.get_current()
var web = context.get_web()
var actions = web.get_userCustomActions();
context.load(web)
context.load(actions)
context.executeQueryAsync(
function () {
var newAction = actions.add();
newAction.set_description('abc123')
newAction.set_location('ScriptLink')
var scriptBlock = 'var headID = document.getElementsByTagName("head")[0];var newScript = document.createElement("script");newScript.type = "text/javascript";newScript.src = "'
scriptBlock += web.get_url() + '/scripts/scriptfile.js?ver=' + ((new Date()) * 1);
scriptBlock += '";headID.appendChild(newScript);';
newAction.set_scriptBlock(scriptBlock)
newAction.update()
context.executeQueryAsync(
function () {
console.log("Success")
},
function () {
console.log('Error')
})
},
function () {
console.log('Error')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment