Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans