Wednesday, October 29, 2014

How to hide Add Existing Associated Ribbon Button for specific Custom Entity in MSCRM 2013/ Use of “Form Entity Context Rule”

Following is the link with helped me solve the issue, however to explain in detail I will take my own example
Consider we have a custom entity called “new_demo” which has 1:N relationship with account , contact and any other custom entity

Now say for example we want to hide the “+ Add NEW DEMO” sign that shows up on the associated view only if the “new_ demo” entity subgrid is placed on account otherwise in all other cases we want to keep showing the  “+ Add NEW DEMO”.

To achieve the same via Ribbon workbench we need to follow the following steps.
·         Create a new solution and add the “new_demo” entity to that solution.

·         Open the solution in Ribbon work bench 2013

·         Select the “new_Demo” entity in the entities section of the ribbon workbench

·         Go to the subgrid section and select the “+ Add NEW DEMO” (note demo will be replaced with the name of the entity you are working with)


·         Clicking on “Customize command” will add a new command to the command tab

·         Select the command and right Click on it to edit display rules


·         Clicking on “Edit display rules will pop up the screen where you can add a new display rule by clicking on “Add New”


·         Click Add new and give a name to the new display rule and then click add step


·         In the steps select “form Entity Context Rule” and then set the values as following 


·         The above values will hide the “+ Add NEW DEMO” button from the associated view of the “new_demo” entity on account entity, on all other entities the button will keep showing up on the associated view of the new_demo entity. You can use the above to hide the button for your specific entity. Similarly changing these values can tweak the results in a way we want to hide/show the button on different entities.

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/" />