1

I need to add both a custom ribbon button to change a field value of all selected items in a list/list-webpart and I'm interested in creating a custom action in the ECB (context menu) and hover panel that shows up over documents to do the same thing.

What is now the proper way of doing this because I'm seeing old examples show Custom Action Ribbon as a template in Visual Studio that's completely configured with an XML, but that template doesn't exist in VS 2015 (MS Dev Tools is installed) and now I'm seeing newer tutorials talking about doing it all through JavaScript using JSOM / REST.

So which is it?

Is the JS script suppose to run every time the site loads or just once to add the custom action? And if it's just once, I'm I suppose to do a check every time to see if this custom action has already been added?

0

Are you consider using javascript, if yes, You might want to try to use javascript

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>  
<script language="javascript" type="text/javascript">  
    $(document).ready(function() {  
        SP.SOD.executeOrDelayUntilScriptLoaded(AddCustomUserAction, "sp.js");  
    });  
    var oListItem;  

    function AddCustomUserAction() {  
        //Get the client context and list object  
        var context = new SP.ClientContext.get_current();  
        var list = context.get_web().get_lists().getByTitle("Check List");  
        //Get the custom user action collection and add the user action  
        var customUserAction = list.get_userCustomActions().add();  
        //Set the location of the user action  
        customUserAction.set_location('CommandUI.Ribbon.ListView');  
        //Add the properties for the custom action  
        var userActionExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' + '<CommandUIDefinitions>' + '<CommandUIDefinition Location="Ribbon.List.CustomizeList.Controls._children">' + '<Button Id="Ribbon.Documents.New.RibbonTest" ' + 'Command="Notify" ' + 'Sequence="0" ' + 'Image16by16="/_layouts/images/NoteBoard_16x16.png" ' + 'Image32by32="/_layouts/images/NoteBoard_32x32.png" ' + 'Description="Shows the ID of the current list." ' + 'LabelText="Show List ID" ' + 'TemplateAlias="o1"/>' + '</CommandUIDefinition>' + '</CommandUIDefinitions>' + '<CommandUIHandlers>' + '<CommandUIHandler Command="Notify" ' + 'CommandAction="javascript:SP.UI.Notify.addNotification(\'ListId={ListId}\');" />' + '</CommandUIHandlers>' + '</CommandUIExtension>';  
        //Add the command UI extension and update the custom user action  
        customUserAction.set_commandUIExtension(userActionExtension)  
        customUserAction.update();  
        //Load the client context and execute the batch  
        context.load(list, 'UserCustomActions');  
        context.executeQueryAsync(function() {  
            console.log("Custom User Action added successfully to ribbon.");  
        }, function(sender, args) {  
            console.log(args.get_message());  
        });  
    }  
</script>  

You can find more detail here: http://www.c-sharpcorner.com/article/create-ribbon-custom-action-using-javascript-object-model-in-sharepoint-2016-and/

  • So this is something that will need to be run on the page every time? – Batman Apr 20 '17 at 23:27

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.