Customization · Dynamics CRM 2011 · Javascript · Ribbon

CRM 2011: Adding Custom Button on Entity Form Ribbon

This post explains how to add a custom button on entity form ribbon.

Things that we have to do:
1. Figure out where we are going to put the new button
2. Add the new button to RibbonDiffXml

1. Where to put the new button
We need to export a solution containing only the entity which form ribbon we want to add a new button.

Since we are adding the new button to the form Ribbon, we need to look at Mscrm.Form.{entity name}.MainTab.

I want to add a new button in the Process section. Therefore I look at Mscrm.Form.{entity name}.MainTab.Workflow.Controls.

To add a new button we need to append _children to the location above.

2. Add the new button to RibbonDiffXml

This is the original RibbonDiffxml

<RibbonDiffXml>
	<CustomActions />
	<Templates>
	  <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
	</Templates>
	<CommandDefinitions />
	<RuleDefinitions>
	  <TabDisplayRules />
	  <DisplayRules />
	  <EnableRules />
	</RuleDefinitions>
	<LocLabels />
</RibbonDiffXml>

The new RibbonDiffXml.
In this sample:
1. Button will call javascript function RunSomething() from webresource newJavascript
2. Button will use webresource newIcon16x16 and newIcon32x32
3. Button will only show if user has write privilege
4. Button will only be enabled on existing record

<RibbonDiffXml>
	<CustomActions>
	  <CustomAction Id="new.CustomAction.NewAction" Location="Mscrm.Form.{entity name}.MainTab.Workflow.Controls._children" Sequence="31">
		<CommandUIDefinition>
		  <Button Id="new.Button.NewAction" 
				  Command="new.Command.NewAction" 
				  LabelText="NewAction" 
				  ToolTipTitle="Tooltip Title" 
				  ToolTipDescription="Tooltip Description" 
				  TemplateAlias="o1" 
				  Image16by16="$webresource:newIcon16x16" 
				  Image32by32="$webresource:newIcon32x32" />
		</CommandUIDefinition>
	  </CustomAction>
	</CustomActions>
	<Templates>
	  <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
	</Templates>
	<CommandDefinitions>
	  <CommandDefinition Id="new.Command.NewAction">
		<EnableRules>
		  <EnableRule Id="new.EnableRule.NewAction" />
		</EnableRules>
		<DisplayRules>
		  <DisplayRule Id="Mscrm.CanWritePrimary"/>
		</DisplayRules>
		<Actions>
		  <JavaScriptFunction Library="$webresource:newJavascript" FunctionName="RunSomething">
		  </JavaScriptFunction>
		</Actions>
	  </CommandDefinition>
	</CommandDefinitions>
	<RuleDefinitions>
	  <TabDisplayRules />
	  <DisplayRules />
	  <EnableRules>
		<EnableRule Id="new.EnableRule.NewAction">
		  <FormStateRule State="Existing" />
		</EnableRule>
	  </EnableRules>
	</RuleDefinitions>
	<LocLabels />
</RibbonDiffXml>

Cheers – Sy

Advertisements

One thought on “CRM 2011: Adding Custom Button on Entity Form Ribbon

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