I have a tab, and in this tab I have 1 question which is called, "nhs_performanceguarantees_y_n_b"
I also have a subgrid in this tab. I am trying to hide this subgrid which is called, "RFP_Guarantee" when nhs_performanceguarantees_y_n_b contains a No, null, blank, undefined.
So if the field is a Yes I want the subgrid to show, if anything else hide it. Below is my script thus far and I can't get it to work.
function GuaranteesonChange()
{
var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();
if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')
{
Xrm.Page.getControl("RFP_Guarantee").setVisible(false);
}
else
{
Xrm.Page.getControl("RFP_Guarantee").setVisible(true);
}
}
Any help is appreciated, thank you.
*This post is locked for comments
Paste this function in the Javascript Library added on the form and Add "HideGrid" function on Form Load Event.
function HideGrid()
{
var new_performanceguarantees=Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b");
if (new_performanceguarantees != null && new_performanceguarantees.getValue() != null) {
if (new_performanceguarantees.getValue() == "Yes") {
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);
}
else {
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);
}
}
}
Please mark as answer if it helps you.
I am not sure I completely understand you business case, but the first question is what type of control is nhs_performanceguarantees_y_n_b?
There are two cases that you might need to call this function, in the form load and in the change event of the above control. This should be able to cover all your cases. You can modify your change even to be more specific:
function GuaranteesOnChange()
{
var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();
switch (Guarantees)
{
case 'Yes':
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);
break;
case 'No':
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);
break;
default: // All Other Cases
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);
break;
}
}
In your onLoad event of the form add the following line:
GuaranteesOnChange(); // Check the value of the performanceguarantees control, and show/hide section/subgrid
If I select Yes and then select the blank option form my drop down field, the subgrid does hide and then comes back when No or Yes is selected again, which isn't correct.
This doesn't seem to work. I put in the below:
function GuaranteesonChange()
{
var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();
if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')
{
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);
}
else
{
Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);
}
}
So when the form loads I have this entire tab hiding. When another field is filled in then the tab shows (this part is working fine). Now in the tab I have a field, which by default it appears as -- (meaning it is blank, null). The grid shows when this happens. I need the subgrid to not show when this happens.
Thank you.
Just use the function that you created:
function GuaranteesonChange()
{
var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();
if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')
{
Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(false);
}
else
{
Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(true);
}
}
In your form designer, on the field that you want to capture the change, click on Change Properties.
On the Events tab (after you have added the JavaScript library as a web resource and to the form), in the Event Handlers section click Add, and select the JavaScript library and enter the function Name (No need to pass execution context).
So what would the hole thing look like then? meaning where would I place that in the above script?
The easiest way is if the subgrid is on a section by its own to hide the section.
Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(false);
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156