Created
July 15, 2015 12:56
-
-
Save wictorwilen/b994571771e5ed0fbc29 to your computer and use it in GitHub Desktop.
Add Custom Action using JSOM
This file contains hidden or 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 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