Back to Basics # 70: Run JavaScript from Ribbon WorkBench in Dynamics CRM


There are many projects which works on earlier versions of Microsoft Dynamics CRM, so to call a JavaScript function from a new custom button that was kept on an entity specific Home Page Grid/Main Form’s Tab / SubGrid Main Tab we must use Ribbon Work Bench extension inside Dynamics Environment. As an example, contact main form was used in a model driven app to explain this scenario.

Step 1:

Login to the required environment and open classic UI of Dynamics CRM Environment and make sure that you have Ribbon Workbench was installed as shown in the figure.

Step 2:

After Step 1, in the same classic view under customizations -> Solutions. Create a new solution and add only contact entity without any components like forms, views etc., as shown in the below figure

Step 3:

After Step 2, Click on Ribbon WorkBench icon that was shown in the above figure and once a new Ribbon Workbench window gets opened click on Open Solution -> New Dialogue with list of Solutions -> Select required solution where contact entity was added in Step 2 as an example open contactribbon solution and place a new button on Form’s Main Tab and name it as Called From RBWBench as shown in the below figure.

Step 4:

After Step 3, click on Commands Section and Click on Add command and after that auto generated Id will be generated, to the right side Properties : Command under Actions Section there will be 2 fields that needs to be selected

  1. Library  : Select the required library (javascript Webresource) that needs to be invoked . Ex : cr5bc_contactmainform js Webresource.
  2. Function Name : Select the required method that was present in the Webresource . Ex : ContosoVaccination.Scripts.ContactForm.handleOnLoad

And then make sure that this command was attached to the button that was created in Step 3 as shown in the below figure.

Step 5:

After Step 4, open the Webresource and add the required code to respond to the button click on contact form with the following code

if (typeof (ContosoVaccination) == "undefined")


    var ContosoVaccination = {__namespace: true};


if (typeof (ContosoVaccination.Scripts) == "undefined")


    ContosoVaccination.Scripts = {__namespace: true};


ContosoVaccination.Scripts.ContactForm =


    handleOnLoad: function ()




    __namespace: true


 function  calledfromRibbonWorkBenchButton()


        alert("called from Ribbon Work Bench using javascript");


As shown in the below figure

Step 6:

After Step 5, save and publish Webresource and then open any contact form and click on custom button and observe the message “Called from Ribbon Work Bench using javascript”as shown in the below figure .


  1. Make sure to publish all customizations and upload javascript file.
  2. Here I have concentrated on calling javascript basic working of workbench extension was needed prior to this implementation.
  3. Also observe, I have considered existing Webresource created earlier, you can also create new javascript Webresource.
  4. Make sure to select a command for a given button in Ribbon Work Bench else , solution which was opened with Ribbon Work Bench will not be published.
  5. Only add entities with out any metadata to the solutions that were used to create new buttons on classic crm forms.

Conclusion: In this way, one can easily run javascript action from Ribbon Work Bench.

One thought on “Back to Basics # 70: Run JavaScript from Ribbon WorkBench in Dynamics CRM

  1. Pingback: Back To Basics : Curated List of Articles in a Single Page – Common Man Tips for Power Platform, Dynamics CRM,Azure

Leave a Reply

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

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

Facebook photo

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

Connecting to %s