Showing Custom Button on Update in CRM 2011

Now let us built on our existing example of adding custom button and adding JavaScript to it.

https://nishantrana.wordpress.com/2010/11/04/adding-my-first-custom-button-in-crm-2011/

https://nishantrana.wordpress.com/2010/11/04/using-javascript-in-a-custom-button-in-crm-2011/

Get the solution file here

http://www.box.net/shared/m9q9otkqfg

Now we want our button to appear only in case of Update form, while creating a new record it shouldn’t appear.

For this we need to first define a DisplayRule in RuleDefinitions.

<RuleDefinitions>

<TabDisplayRules/>

<DisplayRules>


<DisplayRule
Id=MyRule>

<FormStateRule
State=Create
InvertResult=true />

</DisplayRule>

</DisplayRules>

<EnableRules/>

</RuleDefinitions>

This rule we will refer in our CommandDefinition for our button.

<CommandDefinitions>

<CommandDefinition
Id=Cmd_JavaScript>

<EnableRules>

<EnableRule
Id=Mscrm.Enabled/>

</EnableRules>


<DisplayRules>

<DisplayRule
Id=MyRule></DisplayRule>

</DisplayRules>

<Actions>

<JavaScriptFunction
Library=$webresource:new_MyJavaScript
FunctionName=HelloWorld>

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

Now after importing and publishing it

The final RibbonDiffXml looks like this

<RibbonDiffXml>

<CustomActions>

<CustomAction
Id=CA_MyFirstButton
Location=Mscrm.Form.account.MainTab.Save.Controls._children
Sequence=31>

<CommandUIDefinition>

<Button
Id=B_MyFirstButton
Command=Cmd_JavaScript
LabelText=My First Button
ToolTipTitle=My First Button Tool Tip Title
ToolTipDescription=My First Button Tool Tip Description
TemplateAlias=o1
Image16by16=/_imgs/ribbon/saveandclose16.png
Image32by32=/_imgs/ribbon/saveandclose32.png/>

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplates
Id=Mscrm.Templates/>

</Templates>

<CommandDefinitions>

<CommandDefinition
Id=Cmd_JavaScript>

<EnableRules>

<EnableRule
Id=Mscrm.Enabled/>

</EnableRules>

<DisplayRules>

<DisplayRule
Id=MyRule>

</DisplayRule>

</DisplayRules>

<Actions>

<JavaScriptFunction
Library=$webresource:new_MyJavaScript
FunctionName=HelloWorld>

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules/>

<DisplayRules>

<DisplayRule
Id=MyRule>

<FormStateRule
State=Create


InvertResult=true />

</DisplayRule>

</DisplayRules>

<EnableRules/>

</RuleDefinitions>

<LocLabels/>

</RibbonDiffXml>

Hope it helps !


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

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