web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Subgrid ribbon button issue

(0) ShareShare
ReportReport
Posted on by 161

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;    
}
  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    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

  • Verified answer
    Kahspot Profile Picture
    161 on at

    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();

     }

    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 95 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 75

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 58 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans