Wednesday, October 29, 2014

How to refer multiple files in a ribbon workbench/editor or in JavaScript code

Sometimes we need to make a reference to multiple JavaScript files in our code. Say for e.g. you want to refer to some functions written in a common JS file in the new JS code you are writing in an entity specific file. At the form level you can include those files in the form properties however it becomes a problem when we are referring to multiple files from a ribbon. There are multiple ways to resolve the issue
Ribbon Workbench
Ribbon workbench is the preferred tool we use to do customizations of the ribbon in MSCRM 2013.You can refer to multiple file in a ribbon workbench in the following way
·         Add all those web resources you want to refer in a solution.
·         Open that solution in the ribbon workbench
·         Go to the command definition where you want to refer to multiple JS files
·         Right click and then click on “Edit Actions” as shown in image below


·         It will pop up an Actions window which will have an “Add” button at the bottom of the screen.
·         Click on “Add” and it will give you the option to select “JavaScript Function Action”
·         Click on that and then enter “isNaN” as the function name, also select the web resource which you want to refer in your other web resource but do not call any function directly from that web resource. (shown in image below)
·         Set the sequence of the web resources and you are good to go.
Manual Export way:
If however you are not using ribbon workbench then you can manually export the solution with the entity in whose ribbon you want to refer to multiple file and include the file names in the actions tag of the command definition e.g.

<Actions>
       <JavaScriptFunction FunctionName="isNaN" Library="$webresource:demo_sharedLibrary" />
       <JavaScriptFunction FunctionName="Getdetails" Library="$webresource:demo_entity1_Ribbon.js" />
</Actions>
Refer in code
Another approach to address the problem is directly referring the files in the code. Use the following line of code to achieve that

<reference path="../WebResources/demo_sharedLibrary/" />

No comments:

Post a Comment