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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.