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 !
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.
