-->

How to Asynchronously Show a Create New Button On

2019-08-10 20:24发布

问题:

I need to hide the "Add New" button on a sub grid until certain criteria are met. Calling Xrm.Page.ui.refreshRibbon will trigger my JS function defined in my Enable Rule, but I can't get the + button to show up.

Is this unsupported, or is there some methodology to get this to work?

回答1:

Seems like you have to do few extra trick.

Refreshing the subgrid command bar

You will find that when the form is loaded, if there is a value in the attribute you have referenced in your enable rule, the Add New button will be visible. If however the value changes, the sub-grid command bar will not automatically refresh to reflect the new state. Upon adding or deleting rows in the sub-grid the command bar is refresh – but this isn’t much use in this case.

The main form command bar can be refreshed using Xrm.Page.ui.refreshRibbon() however this will not refresh sub-grid command bars. Instead, we can add an onchange event to the fields that are used in our VaueRule and call:

Xrm.Page.data.save();

This will refresh the sub-grids and re-evaluate any of the EnableRules however it will also save any other dirty attributes and so should be used with caution if you do not have auto-save enabled.

Ref: https://ribbonworkbench.uservoice.com/knowledgebase/articles/489288-show-or-hide-the-add-new-button-on-form-sub-grid



回答2:

Arun Vinoth did find a great article to describe the issue, but actually I've found that just calling refresh on the grid itself was all that was actually required.

It's important to note, that this does not re-run the enable rules, just shows the button if the state has changed.