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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Hide/Show Ribbon Button not working and its ASAP

(1) ShareShare
ReportReport
Posted on by 5,516
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
  • 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
11manish Profile Picture

11manish 46 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 35

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 33 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans