Show or hide ‘Add New’ or ‘+’ button on form sub-grid based on the value on the form

Hi,
 
Today I got a requirement to Hide/Show “+” button on the Sub grid based on some conditions.
 
I used Ribbon workbench for doing it. But, unfortunately it was not working. After some search came to know that I am trying to customize wrong button. Actually, we should apply our commands on the highlighted button.

Here are the steps to be followed for hiding and showing the button.
 
Create a Webresource and write you condition in it. Make sure it returns True/False.

function EnableNewButton() {

    return true;
}

Create a solution in CRM and add the required entity and webresource.

Open the same solution in Ribbon Workbench.

Right-Click on the button and click Customize Command.

Its shows all the existing Command rules like Display rules, Enable rules etc..

Right click on the new customized command and click Edit Enable Rules.

Click on Add New button and Select Custom JavaScript Rule.

Change the Id if you wish and Click on Add Step

Select Custom JavaScript Rule.

Select the WebResource and Javascript function name.

Click on Publish.


Done, now the button will be hidden/shown based on the Boolean value that is returning from the JavaScript function.

Hope this helps.
 

Happy CRM’ing
Gopinath 

6 thoughts on “Show or hide ‘Add New’ or ‘+’ button on form sub-grid based on the value on the form

  1. Siva November 27, 2015 / 10:35 am

    Hi GopinathI am getting the following exception while publishing this , could you please help me on this.Reasons:1:The \”Show error message\” and \”Set value\” actions can't be used in a business rule that doesn't have a condition.

    Like

  2. Gopinath November 29, 2015 / 3:37 pm

    Hi Siva,I think, its is related to the business rule on the entity. Check the business rule on the entity and then try to publish.

    Like

  3. crmsample.blogspot.com February 26, 2016 / 7:13 am

    Hi Gopi the button is not hide .Even i am not get any error.My condition :function DisableNewButton(){ var status = Xrm.Page.getAttribute(\”new_statusapprover\”).getValue(); debugger; //if status reason is Approved or Approval Pending if (status == 100000002) { return false; } else { return true; }}Entity name:AccountAttribute name :Statusapprover(Optionset)options:new 100000000, approve for submitted(100000001) ,approve and reject(100000002)Event: onchangehelp me

    Like

  4. crmsample.blogspot.com February 26, 2016 / 7:14 am

    Hi Gopi the button is not hide .Even i am not get any error.My condition :function DisableNewButton(){ var status = Xrm.Page.getAttribute(\”new_statusapprover\”).getValue(); debugger; //if status reason is Approved or Approval Pending if (status == 100000002) { return false; } else { return true; }}Entity name:AccountAttribute name :Statusapprover(Optionset)options:new 100000000, approve for submitted(100000001) ,approve and reject(100000002)Event: onchangehelp me

    Like

  5. Unknown March 2, 2016 / 11:27 am

    Thank you gopi :)Great Post. Its working for me.

    Like

  6. samali March 2, 2020 / 6:25 am

    Hi there. I discovered your web site by way of Google whilst looking for a similar matter, your website got here up. It appears to be good. I have bookmarked it in my google bookmarks to come back then.iot solutions for smart cities

    Like

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s