Using multiple JavaScriptFunction for Actions in CRM 2011 Ribbon.

Hi,

We had a requirement in which we wanted to add some functionality on the existing Distribute Campaign Activity button for Campaign Activity entity.

For e.g. before we start the distribution we wanted to check for a specific value for all the Marketing Lists associated to that Campaign Activity. Based on it we wanted to proceed further or stop the distribution.

So we created a new custom button using the same definitions used for the existing Distribute Campaign Activity button (i.e. same CommandDefinitions and RuleDefinitions). The only thing we added was the new JavaScriptFunction in the Actions menu. It was referring to the function name CheckMLUA inside the webresource name new_CheckML

Now inside this new JavaScriptFunction we wanted to call the CallDistribute function that is being used by the OOB Distribute Campaign Activity button

For this to work we defined the FunctionName as isNAN for campaignactivity.js.

“For each library, add a <JavaScriptFunction Library=”$webresource:webresourceName” FunctionName=”isNaN” /> node. It requires a function name, so we’ve just been putting isNaN in there so there’s no error.”

<JavaScriptFunction
Library=$webresource:new_CheckML
FunctionName=CheckMLUA />

<JavaScriptFunction
FunctionName=isNaN
Library=/_static/ma/campaignactivity/campaignactivity.js>

<CrmParameter
Value=PrimaryEntityTypeCode />

</JavaScriptFunction>

And our function

RibbonDiffXML

</pre>
<RibbonDiffXml>
 <CustomActions>
 <CustomAction Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.CustomAction" Location="Mscrm.Form.campaignactivity.MainTab.Actions.Controls._children" Sequence="41">
 <CommandUIDefinition>
 <Button Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute" Command="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command" Sequence="0" ToolTipTitle="$LocLabels:WWB.Form.campaignactivity.MainTab.Actions.Distribute.LabelText" LabelText="$LocLabels:WWB.Form.campaignactivity.MainTab.Actions.Distribute.LabelText" ToolTipDescription="$LocLabels:WWB.Form.campaignactivity.MainTab.Actions.Distribute.Description" TemplateAlias="o1" Image16by16="/_imgs/MA/CampaignActivityDistribute_16.png" Image32by32="/_imgs/MA/CampaignActivityDistribute_32.png" />
 </CommandUIDefinition>
 </CustomAction>
 </CustomActions>
 <Templates>
 <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
 </Templates>
 <CommandDefinitions>
 <CommandDefinition Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command">
 <EnableRules>
 <EnableRule Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command.EnableRule.FormStateRule" />
 </EnableRules>
 <DisplayRules>
 <DisplayRule Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command.DisplayRule.EntityPrivilegeRule" />
 </DisplayRules>
 <Actions>
 <JavaScriptFunction Library="$webresource:new_CheckML" FunctionName="CheckMLUA" />
 <JavaScriptFunction FunctionName="isNaN" Library="/_static/ma/campaignactivity/campaignactivity.js">
 <CrmParameter Value="PrimaryEntityTypeCode" />
 </JavaScriptFunction>
 </Actions>
 </CommandDefinition>
 </CommandDefinitions>
 <RuleDefinitions>
 <TabDisplayRules />
 <DisplayRules>
 <DisplayRule Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command.DisplayRule.EntityPrivilegeRule">
 <EntityPrivilegeRule EntityName="activitypointer" PrivilegeDepth="Basic" PrivilegeType="Create" />
 </DisplayRule>
 </DisplayRules>
 <EnableRules>
 <EnableRule Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Command.EnableRule.FormStateRule">
 <FormStateRule State="Existing" />
 </EnableRule>
 </EnableRules>
 </RuleDefinitions>
 <LocLabels>
 <LocLabel Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.Description">
 <Titles>
 <Title languagecode="1033" description="Distribute Description" />
 </Titles>
 </LocLabel>
 <LocLabel Id="WWB.Form.campaignactivity.MainTab.Actions.Distribute.LabelText">
 <Titles>
 <Title languagecode="1033" description="Distribute" />
 </Titles>
 </LocLabel>
 </LocLabels>
 </RibbonDiffXml>
<pre>

The helpful links

http://rajeevpentyala.wordpress.com/2012/05/23/loading-dependent-jscript-libraries-in-ribbon-buttons-execution-crm-2011/

http://social.microsoft.com/Forums/is/crmdevelopment/thread/02ed3c05-05c2-4638-a139-e070db4561b0

Bye.


Author: Nishant Rana

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

2 thoughts on “Using multiple JavaScriptFunction for Actions in CRM 2011 Ribbon.”

  1. so the only significance of using the isNaN function specifically is that you needed any legitimate function to call that wouldnt throw an error? perhaps that should be expanded on in your blog entry as its not particularly obvious.

    Like

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