Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Hide/Show Ribbon Button not working and its ASAP

(1) ShareShare
ReportReport
Posted on by 5,007
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
    RudyZhang Microsoft Employee on at
    Hide/Show Ribbon Button not working and its ASAP
    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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,684 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,414 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans