Skip to main content

Notifications

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

Subgrid ribbon button issue

Posted on by 159

Hello,

I am hiding  + button on subgrid ribbon based on condition(Security role + BPF stage) . The problem is that the only way to show or hide + button  on a subgrid ribbon is to save a form.   Please let me know what I am missing in my JS code. Thank you.

function hideAddNewButton(primaryContext) {
    debugger;
    var isButtonEnabled = true;
    var effectiveStage = primaryContext.getAttribute("statuscode").getValue();
    var userRoles=Xrm.Utility.getGlobalContext().userSettings;
    if(Object.keys(userRoles.roles._collection).length>0)
    {
        for ( var rolidcollection in userRoles.roles._collection)
        {
           var currentUserRoles= Xrm.Utility.getGlobalContext().userSettings.roles._collection[rolidcollection].name;    
           if((currentUserRoles == "System Administrator" )|| (currentUserRoles != "System Administrator" && effectiveStage != 803850006)){            
               isButtonEnabled = true;                                             
           }
           else if ((currentUserRoles != "System Administrator" && effectiveStage === 803850006) ){
            isButtonEnabled = false;             
           }      
        }          
    }    
    return isButtonEnabled;    
}
  • Verified answer
    Kahspot Profile Picture
    Kahspot 159 on at
    RE: Subgrid ribbon button issue

    Hello Tamilarasu,

    Thank you for you time . I have already found a solution that works for me . Forgot to update my story.  Here it is :

     function onStageChange(executionContext)

    {

       var formContext = executionContext.getFormContext();

     if(executionContext.getEventArgs().getDirection()==="next")

     {

         formContext.data.entity.save();

     }

    }

  • Suggested answer
    RE: Subgrid ribbon button issue

    Hi Kahspot,

    As per my understanding to your question, you can save your page programatically using the below line of code

    formContext.data.save(saveOptions).then(successCallback, errorCallback);

    In Ribbon Work Bench, You can use EnabledRule to hide or show the button based on the condition. May be the below link will help

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

    If you found this useful, verify and like my answer

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

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