cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RamyaPF
Frequent Visitor

Hide Subgrid Add New for Specific Entities

Hi All,

Please can I know a way to hide the 'Add New (+)' subgrid button of an entity ?

I cannot use Ribbon Workbench as the Add New subgrid button is required in some entities but not in some.

Trying the below javascript on the 'Tab Change' event return Null in the window.parent command for the any combinations I have below. 

Any help will be greatly appreciated.

 

function HideAddButtonSubgrid() {

// Get subgrid control
var subGridCtrl = Xrm.Page.getControl("Subgrid_Portfolio_ProgramRisk");  // This returns control

// If subgrid is not loaded yet, then call same function after some time.
if (subGridCtrl == null) {
setTimeout(HideAddButtonSubgrid, 1000);
return;
}

// Get the add button
//var addButton=window.parent.document.getElementById("Subgrid_Portfolio_ProgramRisk"); //Returns Null
// var addButton = window.parent.document.getElementById("Subgrid_Portfolio_ProgramRisk_addImageButtonImage"); //Return Null
var addButton = window.parent.document.getElementById("id-3723");  //Returns Null

// Hide the button
if (addButton != null)
{
addButton.style.display = 'none';  //Doesn't come into this loop 😞
}
}

4 REPLIES 4
ChrisPiasecki
Super User
Super User

Hi @RamyaPF,

You can use the Ribbon Workbench to register an Enable rule for the entity's subgrid add new button. 

If you want to programmatically control this, you an use a <CustomRule> element and register a JavaScript function from a JavaScript web resource. More information is available below. 

 https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/customize-dev/...

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

EricRegnier
Super User II
Super User II

Hi @RamyaPF,

The code pasted is unsupported and wouldn't recommend it. Even though the button is still used for other entities, you can still use the Ribbon Workbench and add some custom display/enable rule logic which checks the current entity and hides it based on the current entity or other any custom logic.

Here are the quick steps:

  1. Create a new small solution and add only the entity(s) required
  2. Open ribbon workbench and select that solution
  3. Right click on the Add New {0} in the subgrid section and click "Customise Button". The button will then appear in the solution elements pane:
    2020-11-10_16-48-06.png
  4. Right click on the button in the Solution Elements pane and click "Customise Button". It will generate the Command for that button
  5. Select that button's command and add a new Enable Rule
  6. Add a new Custom Rule (JavaScript) step with and point to your JavaScript web resource and function
    1. Add the Primary Control parameter2020-11-10_16-45-16.png
  7. Here's an example of what your function might look like. Note the primaryControl is the formContext

    async function IsButtonVisible(primaryControl) {
       let formContext = primaryControl;

       //some logic
       if (formContext.getAttribute("blabblah").getValue() == null) {
           return false;
       }
       return true;
    }​​

Hope this helps!

RamyaPF
Frequent Visitor

Thank you @ChrisPiasecki and @EricRegnier .

@EricRegnier Thank you for pointing out to 'Customise Command' in Ribbon work bench! It opened the flood gate of options!

I ended up using 'Entity Rule' as below to hide Add new button

RamyaPF_1-1605024753768.png

 

This works perfectly 🙂

But my requirement is little bit complex than that,

In one of tabs for Entity E1 we have 3 subgrids
Subgrid 1 of Entity X related to Entity E1 (allow Add + in subgrid)
Subgrid 2 of Entity X related to Entity E2 (Hide Add new)
Subgrid 3 of Entity X related to Entity E3 (Hide Add new)

 

Please can you advise which Display Rule on Entity X in Ribbon Work bench that I can use?

 

I would have a FormEntityContextRule Rule on the Display Rule to hide based on the parent entity. Hope that works 🙂

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,538)