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 CRM (Archived)
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Hide "New Request Form" button

Posted on by
In ribbon workbench I select entity acwapp_requestform where the subgrid is, and in that subgrid I want to hide the New Request Form button when the subgrid records has status of "Draft", "In Progress", or "Submitted", if the records has status of Rejected or Approved it will still show. Below is my whole code for javascript
function hideSubgridRibbonInRequest() {
    try {
        var formContext = Xrm.Page;
 
        var parentEntityName = formContext.data.entity.getEntityName().toLowerCase();
 
        console.log("Parent Entity Name:", parentEntityName);
 
        if (parentEntityName === "acwapp_lease") {
            var subgridControl = formContext.getControl("RequestForm");
 
            console.log("Subgrid Control:", subgridControl);
 
            if (subgridControl && subgridControl.getGrid()) {
                var gridRows = subgridControl.getGrid().getRows().get();
 
                console.log("Grid Rows:", gridRows);
 
                if (gridRows.length === 0) {
                    return true; // Show "New" button if there are no rows
                }
 
                var hideNewButton = true; // Assume initially we should hide the "New" button
 
                for (var i = 0; i < gridRows.getLength(); i++) {
                    var statusValue = gridRows.get(i).getData().getEntity().attributes.getByName("acwapp_status").getValue();
 
                    console.log("Status Value:", statusValue);
 
                    // Check if status is Draft, In Progress, or Submitted
                    if (statusValue === 557130000 || statusValue === 557130001 || statusValue === 557130002) {
                        hideNewButton = false; // Found an eligible status, show the "New" button
                        break; // No need to check further
                    }
                }
 
                return hideNewButton; // Return true to hide "New" button, false to show it
            }
        }
 
        return true; // Default behavior: hide "New" button
    } catch (error) {
        console.error("Error in hideSubgridRibbonInRequest:", error);
        throw error;
    }
}
Categories:

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans