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,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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans