How to Create a Selection Sensitive Ribbon Button on an Entity Home Page

The Ribbon Workbench tool has been a core part of the Dynamics platform for many years, allowing for  significant  ribbon customizations.  One of its lesser-used features is the ability to create buttons that are sensitive to the context of a subgrid, allowing users to perform actions on multiple related records at once.  This means that a user could, for example, navigate to an Account record and perform an action on a subset of its related orders, like sending information about each selected order to the email address on the account. 

 However, this functionality does not allow a user to utilize an account hierarchy to send this information to a parent account or perform actions on unrelated orders.  System configurators could create a new relationship between the account and order tables that refers specifically to the parent, though this introduces schema complexity and has limited flexibility.  Another option, and the one we will be covering in this blog, is to create a ribbon button on the  childthe child table’s home page (Orders, in this case) that is sensitive to the context of the entire table view.  This process is similar to doing so on a form’s subgrid but materially different such that it makes sense to cover separately. 

 

Find out more about our Dynamics 365 offerings
 

  1. Create a new JavaScript resource or modify an existing one by adding the following basic function: 

processBulkAction: function (selectedItems) { 

    if (selectedItems && selectedItems.length) { 

        const selectedItemsJoined = "'" + selectedItems.join("','") + "'"; 

        // use selectedItemsJoined to get data from the selected order headers if desired via a web API query 

    } else { 

        alert("Please select at least one order header record."); 

    } 

} 

2. Create a new solution for the ribbon workbench and include whichever table’s home page you would like the button to exist on (e.g., Order): 

image002

 

3. Open the solution in the Ribbon Workbench tool.   

a. If this tool is not already installed in your environment, you can get it here.  Once installed, it will be an available option in the Solutions section of your environment’s advanced settings: 

image004

         b. The first thing Ribbon Workbench will ask you to do is select a solution; select the one you created for this purpose. 

image006

      c. Create a new command.   

          i. In the Actions section, click Add Action and choose JavaScript Action.  Find the JavaScript resource that  contains the function we created earlier and add the function name to the appropriate field. 

         ii. Within the Javascript Action, click Add Parameter and choose CRM Parameter.  Select SelectedControlSelectedItemIds as the value. 

image008

     d. Create a new button. 

         i. Click and drag the BUTTON object from the Toolbox into the top bar, where it says Mscrm.HomepageGrid.salesorder.MainTab: 

image010

         ii. Click on the newly created button in the Solution Elements section and select the new command in the Command field.  Rename the button if desired via the Label field. 

image012

      e. Once finished, click the Publish button in the top navigation bar.  This will link the ribbon button to the javascript function, and any subsequent changes made to that function will be reflected in the functionality of the button. 

Find out more about our Dynamics 365 offerings

Conclusion 

This process will result in a new ribbon button that is ready for whatever logic is appropriate in the JavaScript, with the selected record IDs passed in when it is clicked We have helped customers use this functionality for various purposes, including emailing records to hierarchy accounts, creating activities regarding unrelated records, and validating selection information that can span multiple parent tables. 

If you have any questions, leave a comment below. You can also connect with our BOLDEnthusiasts by clicking here. 

 

Leave a Reply

Your email address will not be published.