Matt
Matt

Reputation: 1370

CRM 2011 Ribbon Enable Rule on grid does not fire for each change of line

I'm trying to add a button to a CRM 2011 ribbon on a grid view. I want the button to be conditionally enabled or disabled for some critera which may differ for each row in the grid.

I have the EnableRule setup and working correctly for both single and multiple selections - the problem is that the rule only fires when the number of items selected changes. So it works the first time when the user selects one row, but does not fire again until the user selects a different number of rows - ie. changing the single selected row does not fire the enable rule as expected.

Edit - My enable rule XML is as follows

        <EnableRule Id="cnet.exception.grid.EnableReviewButton">
          <CustomRule FunctionName="EnableReviewButtonOnGrid" Library="$webresource:cnet_ribbon_js" Default="false">
            <CrmParameter Value="SelectedControlSelectedItemIds" />
          </CustomRule>
        </EnableRule>

Update Ok, the rule does fire once per row the first time the user clicks in the grid - what was preventing this happening was having a debug "alert" statement in the JS function that the enable rule was calling. Now just need to figure out how to get the id of the row that is being processed...

Any thoughts...?

Thanks

Upvotes: 2

Views: 2971

Answers (4)

Grigory
Grigory

Reputation: 550

Yes, your RibbonDiffXml would be very helpfull. But, from what you're saying I think you need a custom script Enable/Disable rule. Something like this

<EnableRules>
      <EnableRule Id="Mscrm.AddExistingCustomRule">
       <CustomRule FunctionName="HideExisting" Library="$webresource:new_CustomRule.js" Default="false" >
          <CrmParameter Value="PrimaryEntityTypeCode" />
        </CustomRule>
      </EnableRule>
 </EnableRules>

See the full post here Enable/Disable Out of Box buttons (Sub Grid) based on a custom rule in crm 2011

Just discovered that there is a function called refreshRibbon() wich you can call to refresh RibbonState. Just like this:

Xrm.Page.ui.refreshRibbon();

Upvotes: 0

Greg Owens
Greg Owens

Reputation: 3878

Now just need to figure out how to get the id of the row that is being processed...

Hi Matt I'm not clear on what you're now expecting your script to do. As this is an enable rule, it will be used to enable or disable the ribbon button by evaluating criteria against all of the selected items in the grid.

You have, correctly I believe, opted to set a CrmParameter to pass SelectedControlSelectedItemIds to your enable script. As I'm sure you know (since you say your enable rule is working correctly for single selections) SelectedControlSelectedItemIds is a string array of guids and this allows you to iterate all selections and collectively evaluate your rule against each selected item if you wish.

What is unclear to me is why you need to know the id of the (presumably) single row that is "being processed" (i.e. the last selected / deselected item?). I would presume that if one item in the selection fails the "enable" criteria encapsulated in your script, then the script should return false and therefore isolating the last [de]selection is redundant.

Did I misunderstand your requirement? :-/

Upvotes: 1

Paul Way
Paul Way

Reputation: 521

Sounds like your Rule Definition isn't right. The selectionCount rule is firing, but not your CustomRule (or whatever you have).

Can you post your XML?

Upvotes: 0

Related Questions