Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Hide add new button on a sub grid based on status reason value

(0) ShareShare
ReportReport
Posted on by 285

Hi New to ribbon workbench, I want to Hide custom entity add new "+" button on a sub-grid based on lead status reason custom value = "100,000,002"

Can someone please guide how to achieve this?

Should I just use ribbon workbench? or do I need to load any web resource javascript file?

Thank you in advance.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide add new button on a sub grid based on status reason value

    I'm glad I was able to help!

  • nidnani Profile Picture
    285 on at
    RE: Hide add new button on a sub grid based on status reason value

    Hey Andrew.

    A big thank you, my friend. It's working fine now. I used your code and added the CRM parameter. Works perfectly fine.  I tested a bunch of orders with different status and works well. Thank you so much.

    I also subscribed to your youtube channel to learn more from you.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide add new button on a sub grid based on status reason value

    You can use any. Both codes do the same thing but I prefer second one.

  • nidnani Profile Picture
    285 on at
    RE: Hide add new button on a sub grid based on status reason value

    Sure, below is the command screenshot.

    8640.Command.PNG

    And if I am using primary control which code should I use the one below 1 or 2 ?

    1. function hideSub(primaryControl)

    {

    var formContext = primaryControl;

    return (formContext.getAttribute(“statuscode”).getValue() === 100000002);

    }

    2. function hideSub(formContext)

    {

    return (formContext.getAttribute("statuscode").getValue() === 100000002);

    }

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide add new button on a sub grid based on status reason value

    According you your last screenshot (with the rule) you don't pass the context into the function. Check this article please - blog.magnetismsolutions.com/.../getting-dynamics-365-formcontext-from-ribbon-workbench

    Also just as an additional check can you please provide screenshot of Mscrm.AddNewRecordFromSubgridStandard command?

  • nidnani Profile Picture
    285 on at
    RE: Hide add new button on a sub grid based on status reason value

    Hi Andrew.  Yes, I have updated it to statuscode. Below are all the screen shots.

    1. Web resource

    2. Lead Statuscode

    3. RWB Command settings - All the display rules and enable rules IsCore is set to True as described in the link.

    Custom entity(sfiorder) subgrid added to Lead form is still showing Add New on the Lead page will all the status.

    JS-WR.PNG

    Lead-Statuscode.PNG

    RWB-Command.PNG

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide add new button on a sub grid based on status reason value

    As we discussed earlier it should be statuscode, not statecode so try the code

    function hideSub(formContext) {

    return (formContext.getAttribute("statuscode").getValue() === 100000002);

    }

    Also don't forget to place the field on the form.

  • nidnani Profile Picture
    285 on at
    RE: Hide add new button on a sub grid based on status reason value

    Andrew, I fixed the code error by re-adding CRM parameters for Add New Command. 

    However, I am still not able to achieve the requirement. 

    So far, I added the JS Web Resource with the below code and followed the link you provided. But still not working.
    ribbonworkbench.uservoice.com/.../489288-show-or-hide-the-add-new-button-on-form-sub-grid

    function hideSub(formContext)

    {

    return (formContext.getAttribute("statecode").getValue() === 100000002);

    }

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide add new button on a sub grid based on status reason value

    I have no idea what could cause this.

  • nidnani Profile Picture
    285 on at
    RE: Hide add new button on a sub grid based on status reason value

    Now getting below error in CRM when clicking on Add New Record

    TypeError: Cannot read property 'getRelationship' of undefined

       at OpenLibrary.addNewFromSubGridStandard (test.crm.dynamics.com/.../Main_system_library.js:1:281229)

       at sl.executeFunction (test.crm.dynamics.com/.../app.js

       at sl.execute (test.crm.dynamics.com/.../app.js

       at test.crm.dynamics.com/.../4.js

       at i (test.crm.dynamics.com/.../app.js

       at test.crm.dynamics.com/.../4.js

       at Array.forEach (<anonymous>)

       at test.crm.dynamics.com/.../4.js

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 106

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

Overall leaderboard

Product updates

Dynamics 365 release plans