Advertisements
Home > CRM 2011, Ribbon > Disabling Assign ribbon button based on custom logic using jscript CRM 2011

Disabling Assign ribbon button based on custom logic using jscript CRM 2011

In one of my requirement, I have to enable/disable “Assign” button on “Account” form based on one of my option set value (i.e.,accountcategorycode)

Assign Button On Account Form

Assign Button On Account Form

I followed below steps to achieve the requirement

  • Get the Account “Assign” ribbon button details from “sdk\resources\exportedribbonxml\ accountribbon.xml” file from the SDK
    • Open a note pad and copy below two nodes for reference
    • Copy <Button Id=”Mscrm.Form.account.Assign”> tag
    • Copy <CommandDefinition Id=”Mscrm.AssignPrimaryRecord”> tag
  • Create a new jscript webresoure “new_Account_Ribbon” with function “enableAssignButton” and publish
    • If the function returns true the “Assign” button gets enabled else disabled
    • Define your own custom logic (Refer my custom logic below)

function enableAssignButton() {

try {

var fldCategory = Xrm.Page.data.entity.attributes.get(“accountcategorycode”);

if (fldCategory && fldCategory.getValue()) {

if (fldCategory.getValue() == 100000007) {

return true;

}

}

return false;

} catch (e) {

alert(“Error while enabling Assign button: ” + e.description);

}

}

  • Create a new solution and include “Account” entity and export as Unmanaged solution
  • Extract the zip folder and open “customizations.xml” using visual studio
  • Navigate to <RibbonDiffXml> node
  • Replace with below node (Refer comments to understand)

<RibbonDiffXml>

<CustomActions>

<!– Location will be ID of the Button–>

<CustomAction Location=”Mscrm.Form.account.Assign” Id=”Form.account.DisableAssign”>

<CommandUIDefinition>

<!– Paste the Assign button tag which you copied to notepad–>

<Button Id=”Mscrm.Form.account.Assign” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

ToolTipDescription=”$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Assign”

Command=”Mscrm.AssignPrimaryRecord” Sequence=”33″

LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign”

Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign” Image16by16=”/_imgs/ribbon/Assign_16.png” Image32by32=”/_imgs/ribbon/Assign_32.png” TemplateAlias=”o1″ />

</CommandUIDefinition>

</CustomAction>

</CustomActions>

<Templates>

<RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>

</Templates>

<CommandDefinitions>

<!– Paste the Assign button Command Definition which you copied to notepad –>

<CommandDefinition Id=”Mscrm.AssignPrimaryRecord”>

<EnableRules>

<EnableRule Id=”Mscrm.FormStateNotNew” />

<EnableRule Id=”Mscrm.AssignPrimaryPermission” />

<EnableRule Id=”Mscrm.NotOffline” />

<!– Add new Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”/>

</EnableRules>

<DisplayRules>

<DisplayRule Id=”Mscrm.AssignPrimaryPermission” />

<DisplayRule Id=”Mscrm.NotClosedActivity” />

</DisplayRules>

<Actions>

<JavaScriptFunction FunctionName=”assignObject” Library=”/_static/_forms/form.js”>

<CrmParameter Value=”PrimaryEntityTypeCode” />

</JavaScriptFunction>

</Actions>

</CommandDefinition>

</CommandDefinitions>

<RuleDefinitions>

<TabDisplayRules />

<DisplayRules />

<EnableRules>

<!– Define Enable Rule–>

<EnableRule Id=”Form.account.AssignButton.EnableRule”>

<CustomRule Library=”$webresource:new_Account_Ribbon” FunctionName=”enableAssignButton“>

</CustomRule>

</EnableRule>

</EnableRules>

</RuleDefinitions>

<LocLabels />

</RibbonDiffXml>

🙂

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: