Friday 13 April 2012

Enable/Disable Ribbon button From Entity Form

Today I need to Enable/Disable Ribbon on Entity Form and after some research i found two mathod that are very helpfule to me to resolve my issue

1) using CustomRule

using this rule we can call our javascript function and check required condition. According to condition return true (to enable ribbon button) or false (to disable ribbon button)

With CustomRule we also able to send differen type of paramerters like :

<CrmParameter
 Name = "String"
 Value= ["CommandProperties" |
         "PrimaryEntityTypeCode" |
         "PrimaryEntityTypeName" |
         "PrimaryItemIds" |
         "FirstPrimaryItemId" |
         "PrimaryControl" |
         "PrimaryControlId" |
         "SelectedEntityTypeCode" |
         "SelectedEntityTypeName" |
         "FirstSelectedItemId" |
         "SelectedControl" |
         "SelectedControlSelectedItemCount" |
         "SelectedControlSelectedItemIds" |
         "SelectedControlSelectedItemReferences" |
         "SelectedControlAllItemCount" |
         "SelectedControlAllItemIds" |
         "SelectedControlAllItemReferences" |
         "SelectedControlUnselectedItemCount" |
         "SelectedControlUnselectedItemIds" |
         "SelectedControlUnselectedItemReferences" |
         "OrgName" |
         "OrgLcid" |
         "UserLcid"]
 />

<EnableRules>
<EnableRule Id="Mscrm.Isv.account.Form.CustomButton.Enable">
<CustomRule FunctionName="isenable" Library="$webresource:new_account.js">
                <CrmParameter Value="SelectedControlSelectedItemCount" />
              </CustomRule>

</EnableRule>
</EnableRules>

Javascript function
function isenable(_itemcount) {
    if (itemcount== 1) {
//write you logic
return true;
    }
    else {
        return false;
    }
}
2) using ValueRule

<EnableRules>
<EnableRule Id="Mscrm.Isv.account.Form.CustomButton.Enable">
<ValueRule Field="new_customerrel" Value="3" Default="0" />
</EnableRule>
</EnableRules>

No comments:

Post a Comment