I wanted to add an action button in the Site Actions menu and I found a code easy to incorporate :
$(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomUserAction);
});
function AddCustomUserAction() {
//Get the client context and web object
var clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
//Get the custom user action collection and add the new custom action to it
var collUserCustomAction = oWeb.get_userCustomActions();
var oUserCustomAction = collUserCustomAction.add();
//Specify the location and properties for the new custom action
oUserCustomAction.set_location('Microsoft.SharePoint.StandardMenu');
oUserCustomAction.set_sequence(101);
oUserCustomAction.set_group('SiteActions');
oUserCustomAction.set_title("New Action Item");
oUserCustomAction.set_url("/site/linksite.html");
oUserCustomAction.update();
//Load the client context and execute the batch
clientContext.load(collUserCustomAction);
clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
}
from Priyaranjan K S . Except putting the code in Site Asset, it put it in Style Library. Afterwards, I tried to modify the title, but it duplicated... I deleted the content editor web part containing the code but all the duplicated are still in my Site Actions menu..
I tried the code and changee ".add" but ".delete" or ".deleteobject" and a few codes from the internet without success... Can someone please help me? I am not sure where went wrong... Maybe I should have include the code in a content editor web part from the same page as where I put the "addcustomaction" even though I deleted it already? I am using SharePoint 2010 and i am really limited in usage.
Here is one of those I tried :
function deleteUserCustomAction() {
this.clientContext = new SP.ClientContext(siteUrl);
var oWebsite = clientContext.get_web();
this.collUserCustomAction = oWebsite.get_userCustomActions();
clientContext.load(oWebsite,'UserCustomActions','Title');
clientContext.executeQueryAsync(Function.createDelegate(this, this.deleteCustomAction), Function.createDelegate(this, this.onQueryFailed));}
}
function deleteCustomAction() {
var customActionEnumerator = collUserCustomAction.getEnumerator();
while (customActionEnumerator.moveNext()) {
var oUserCustomAction = customActionEnumerator.get_current();
if (oUserCustomAction.get_title() == 'New Menu Item') {
oUserCustomAction.deleteObject();
clientContext.load(oUserCustomAction);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
from Kodono