четверг, 17 декабря 2020 г.

Кнопка на Ribbon (userCustomActions только с помощью JS)

Появилась задача, что бы сотрудники компании могли распечатать заявки согласно определенной формы. При этом была возможность выбрать сразу несколько и распечатать.

Как основное решение для формы печати было React приложение, размещенное на страницу, а в представлении добавил кастомную кнопку на риббон которая отрывала новый таб с требуемой страницей и передавала ID выделенных элементов как параметр.


Что бы добавить кнопку нужно единожды выполнить код в консоли:


 //Get the client context and list object  
        var context = new SP.ClientContext.get_current();  
        var list = context.get_web().get_lists().getByTitle(_spPageContextInfo.listTitle);  
        //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 = '' + 
                                        '' + 
                                            '' + 
                                                '' + 
                                            '' + 
                                        '' + 
                                        '' + 
                                    '' + 
                                    '';  
        //Add the command UI extension and update the custom user action  
        customUserAction.set_commandUIExtension(userActionExtension)  
        customUserAction.set_title("Распечатать заявки"); 
        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());  
        });  

при желании можно поправить параметры кнопки (при каком условии она активна)



 


Комментариев нет:

Отправить комментарий