Showing posts with label ribbon with Custom button and javascript. Show all posts
Showing posts with label ribbon with Custom button and javascript. Show all posts

Friday, December 28, 2012

Adding button/Javascript to a Ribbon


Replace the <RibbonDiffXmlwith the below code.It will add the button on Account main form with javascript code

<RibbonDiffXml>
<CustomActions>
<CustomAction Id="CA_MyFirstButton" Location="Mscrm.Form.account.MainTab.Save.Controls._children" Sequence="31">
<CommandUIDefinition>
<Button Id="B_MyFirstButton" Command="MSCRM.Form.account.MainTab.Save.Controls._children" 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="MSCRM.Form.account.MainTab.Save.Controls._children">
<EnableRules />
<DisplayRules />
<Actions>
<JavaScriptFunction FunctionName="hello" Library="$webresource:new_test">
<CrmParameter Value="CommandProperties"></CrmParameter>
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules/>
<DisplayRules/>
<EnableRules/>
</RuleDefinitions>
<LocLabels/>
</RibbonDiffXml>

create a web resource test and add the below function

function hello(){
alert("My First Button with Custom button");
}

whenever you click on the custom button it shows an alert