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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Hide/Show Ribbon Button not working and its ASAP

(1) ShareShare
ReportReport
Posted on by 5,514
Hi All, This Solution required ASAP.
 
I have a subgrid on Form A entity and based on the record count in Subgrid i need to Show/Hide +Generate button.
 
If Record count>0 
then 
show +Generate Button 
else
Hide +Generate Button.
 
I added below code but that is not working
------------------------------------------------------------
function ShowGenerateButton(context) { 
    try {
var gridContext = context.getControl(/Section Name/);// get the grid context
var GridOnloadFunction = function () {
        if (context != null && context != undefined && context.getControl(/Section Name/) != null
            && context.getControl(/Section Name/) != undefined) {
            let count = context.getControl(/Section Name/).getGrid().getTotalRecordCount();
            if (count > 0) {
                return true;
            }
            else {
                return false;
            }
        }
    };
    gridContext.addOnLoad(GridOnloadFunction); //run onload of subgrid
}
catch (error) {

};
-------------------------------------------------------------------
I added Enable Rule command and Parameter as Primary control in Ribbon workbench
 
Any quick suggestion will be marked as verified
 
 
Thanks
Sandeep
I have the same question (0)
  • RudyZhang Profile Picture
    Microsoft Employee on at
    Hi,
     
    Regarding your question about showing the hidden button not working
     
    Our team has tried to modify your code, and the modified code is as follows
    function ShowGenerateButton(context) {
        try {
            var gridContext = context.getFormContext().getControl("your_subgrid_name");
            var GridOnloadFunction = function () {
                if (gridContext != null && gridContext != undefined) {
                    let count = gridContext.getGrid().getTotalRecordCount();
                    var generateButton = context.getFormContext().ui.controls.get("your_generate_button_name");
                    if (count > 0) {
                        generateButton.setVisible(true);
                    } else {
                        generateButton.setVisible(false);
                    }
                }
            };
            gridContext.addOnLoad(GridOnloadFunction);
        } catch (error) {
            console.log(error);
        }
    }
    In addition, don't forget to replace "your_subgrid_name" and "your_generate_button_name" with the actual names of the subgrid and generate button controls, respectively.
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Rudy Zhang

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans