Pass Execution Context to JS Script function as a parameter from a Ribbon button in Dynamics 365 | Ribbon Workbench

One of the most common searches around customizing ribbon buttons is to send the Execution Context / Form Context as a parameter to the JavaScript function your Ribbon button is set to call.

Pass Form Context to the JS in Ribbon

Let’s see how you can pass form context as a parameter to the JS method on from your Ribbon button

  1. Let’s say you have a ribbon on the Opportunity that does something based on budget, so I’ve called it Budget.

  2. In the Ribbon Workbench, the button is calling the command which has a JS Function tied to it. Add a CRM Parameter to the JavaScript Action

  3. Once you select CRM Parameter, you’ll need to pass on the Primary Control as shown below

  4. Then, it’ll look like this on your JS Function

Accessing Form Context

Let’s say you have opened the Dev Tools on your browser by pressing F12, then click the button (assuming you either have set a breakpoint inside the function or using debugger; to stop at a point inside the function that button calls). And then you click the button


Once you debug, you’ll see this when you hit the debugger when you function is called.
The debugger will be hit

And if you check in the Console, you’ll see the complete context passed to the function

Hope this helps!

Here are some Ribbon Workbench related posts you might want to check –

  1. Pass selected rows’ GUIDs to ribbon button in D365 | Ribbon Workbench
  2. Debug Ribbon button customization using Command Checker in Dynamics 365 CE Unified Interface
  3. Show Ribbon button only on record selection in Dynamics CRM
  4. Hide Custom Ribbon Button [Easy Way] – Ribbon Workbench
  5. Enable Flow button on D365 Ribbon
  6. [SOLVED] Navigating URL from Ribbon’s custom button in Dynamics for Phones app
  7. Fix Ribbon icons on the Unified Interface in D365 CE
  8. D365 Ribbon Button shortcut to open a Document in SharePoint Online

Thank you!

Pass selected rows’ GUIDs to ribbon button in D365 | Ribbon Workbench

Whenever your Ribbon button customization involves doing something to selected records, here’s the most common application that you need to take action on the selected record’s GUIDs.

Here’s how –

CRM Parameter

In Ribbon Workbench, let’s say you have a button command which is attached to a button and it calls a method ‘process’ which looks like this (it will be your method in your case)

  1. In Commands, Custom JavaScript Action will have a CRM Parameter called as SelectedControlSelectedItemIds [pretty self explanatory 😊]
    undefined


    And it’ll pass data of the selected GUIDs in my data variable passed to the method.
    undefined

Read the GUIDs

Here’s my sample code where I intend to read it from the function I used to call when user clicks on the ribbon button

  1. Now, let’s say I select a few records on the Main Sub-grid where I’ve put my button on.
    undefined

  2. Now, on clicking it, it’ll pass the three selected records’ GUIDs to the method that the button is calling. You can read it from the data parameter
    undefined
  3. You can further read from this array and use it to perform your operations.

Hope this was easy. Here are some more Ribbon Customization related posts you might want to look at –

  1. Debug Ribbon button customization using Command Checker in Dynamics 365 CE Unified Interface
  2. Show Ribbon button only on record selection in Dynamics CRM
  3. Hide Custom Ribbon Button [Easy Way] – Ribbon Workbench
  4. [SOLVED] Navigating URL from Ribbon’s custom button in Dynamics for Phones app
  5. Fix Ribbon icons on the Unified Interface in D365 CE
  6. D365 Ribbon Button shortcut to open a Document in SharePoint Online
  7. Pass data to HTML Web Resource using browser’s sessionStorage in Dynamics 365 CE

Thank you!!

Show Ribbon button only on record selection in Dynamics CRM

One of the most common asks is to show ribbon buttons to only be shown when at least 1 record in Dynamics 365 ribbon button are selected.
buttonShow

Here’s how you can do it –

Enable Rule in Ribbon Workbench

This can be achieved using Enable Rule for the button you wish to show on selection using Ribbon Workbench.

Let’s say your button ‘Promote’ (in this case) is on the Main View of the Account entity. You can add the following Enable Rule to the command –
enableRuleBound

And in the actual Enable Rule, you can select the SelectionCountRule to make this happen. You can set the minimum value to 1 so that it appears when at least 1 record is selected.
acutalEnableRule

Result

Now, if you see – By default, the button is hidden –
buttonHidden

Now, as you can see, only when at least 1 record from the view is selected, the button is visible.
buttonShow

In case you are looking to hide a custom button, check this post – Hide Custom Ribbon Button [Easy Way] – Ribbon Workbench

Hope this helps!!