Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

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

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
    a33ik 84,323 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
    nidnani 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
    a33ik 84,323 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
    nidnani 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
    a33ik 84,323 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
    nidnani 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
    a33ik 84,323 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
    nidnani 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
    a33ik 84,323 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
    nidnani 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans