Dynamics CRM 2011 · Javascript · Ribbon · Workaround

CRM 2011: Custom Ribbon Enable Rule Javascript Check Relationship (Workaround)

This post talks about adding a custom button on an entity SubGrid Ribbon and how to determine the right relationship to enable the custom button.

Let’s just say we have two entities; A and B.
A has a one-to-many and a many-to-many relationship with B; lets call it new_a_b and new_as_bs respectively.
We want a custom button on B’s subgrid that can be clicked for the many-to-many relationship, but not the one-to-many. This is how (more of a workaround).

Ribbon customization is one of the great feature of CRM 2011. We can add a custom button and manage whether it’s enabled or not using EnableRule tag in the RibbonDiffXml. One of the features that makes EnableRule very powerful is the CustomRule that calls JavaScript function to determine whether the button should be enabled.

<EnableRule Id="new.CustomAction.EnableRuleOne">
  <CustomRule Library="$webresource:newJavascriptWebResource.js" FunctionName="GetButtonEnable" Default="false">
	<CrmParameter Value="SelectedControl"/>

One of the parameter you can pass on to the JavaScript function is SelectedControl. This passes the subgrid control. This control does not have any information about what relationship it representing, but its auto-generated id format is something like crmGrid[relationshipName].

So we can determine whether it’s the right relationship with this method.

function GetButtonEnable(selectedControl) {
    var controlId = selectedControl.get_id();

    return controlId.endsWith("new_as_bs");

Cheers – Sy


One thought on “CRM 2011: Custom Ribbon Enable Rule Javascript Check Relationship (Workaround)

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s