0

does anybody know how can I add a new item to list actions menu with JSOM. I am able to add a custom action to a ribbon or to a list item menu (ECB), but I cannot find any reference how to add a new item to this menu.

enter image description here

So far, I have this code that I test in a console, and even though it returns a success, nothing is added

    var siteUrl = "https://mysharepoint"
var clientContext = new SP.ClientContext(siteUrl);
var oWebsite = clientContext.get_web();
this.oList = oWebsite.get_lists().getByTitle('List');
var collUserCustomAction = oList.get_userCustomActions();

var oUserCustomAction = collUserCustomAction.add();
oUserCustomAction.set_location('List.Actions.Menu');
oUserCustomAction.set_sequence(100);
oUserCustomAction.set_title('My First User Custom Action');
oUserCustomAction.set_url(siteUrl + '/_layouts/MyPage.aspx');
oUserCustomAction.update();

clientContext.load(oList, 'Title' ,'UserCustomActions');

clientContext.executeQueryAsync(function(){alert("done")}, function(){alert("done")});

thanks for any suggestions

1

Your location is wrong. The correct location is Microsoft.SharePoint.StandardMenu with group ActionsMenu.

Try this one here:

var siteUrl = "http://mysharepoint"
var clientContext = new SP.ClientContext(siteUrl);  
var oWeb = clientContext.get_web();  
var oList = oWeb.get_lists().getByTitle('List');  
var userCustomActionColl = oList.get_userCustomActions();  
var oUserCustomAction = userCustomActionColl.add();  
oUserCustomAction.set_location('Microsoft.SharePoint.StandardMenu');  
oUserCustomAction.set_group('ActionsMenu');
oUserCustomAction.set_sequence(100); 
oUserCustomAction.set_title("My First User Custom Action");  
oUserCustomAction.set_url(siteUrl + '/_layouts/MyPage.aspx');   
oUserCustomAction.update();
clientContext.load(userCustomActionColl); 
clientContext.executeQueryAsync(
    function(){
        console.log("success")
    }, 
    function(args){
        console.log('failure')
    }
);

The sequence property however doesn't seem to have any effect. That means that you can't specify where in the menu the new button will appear. Hence, it will be added to the bottom.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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