web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide section based on multiple conditions

(0) ShareShare
ReportReport
Posted on by 27

Hi everyone,

Using Jscript, I want to hide/show a section based on:

  1. Whether a single choice column equals 1
  2. Whether the value in a Dataverse currency column is greater than 20,000,000

I have the first part working:

function ShowHideLabel() {
    var choiceType = Xrm.Page.getAttribute("new_businesscasecategory").getValue(); //replace with the logical name of the choice field 
    if (choiceType != null) {
        if (choiceType == "1") {  // replace with the Value for which you want to display webresource. This would be the associated integer value for the choice field in dataverse
            Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_pic").setVisible(true); // replace with TabName and sectionName
        } else {
            Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_pic").setVisible(false); // replace with TabName and sectionName
        }
    }
    else {   // For null value webresource will not display           
        Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_pic").setVisible(false); // replace with TabName and sectionName
    }
}

But my code is incorrect for the second condition. Could anyone help? Unfortunately my expertise with JScript is lacking.

function Show_UnderToleranceSection() {
    var choiceType = Xrm.Page.getAttribute("new_businesscasecategory").getValue(); //replace with the logical name of the choice field 
    var costvalue = Xrm.Page.getAttribute("cr37a_costcovered").getValue();  
if (choiceType != null || costvalue != null) {
        if (choiceType == "1" && costvalue < 20000000) {  // replace with the Value for which you want to display webresource. This would be the associated integer value for the choice field in dataverse
           Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_under_tolerance").setVisible(true); // replace with TabName and sectionName
        } else {
            Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_under_tolerance").setVisible(false); // replace with TabName and sectionName
        }
    }
    else {   // For null value webresource will not display           
        Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_under_tolerance").setVisible(false); // replace with TabName and sectionName
    }
}

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide section based on multiple conditions

    Hello,

    You can use something like the following:

    function Show_UnderToleranceSection() {
        var choiceType = Xrm.Page.getAttribute("new_businesscasecategory").getValue();
        var costvalue = Xrm.Page.getAttribute("cr37a_costcovered").getValue();  
    
        var sectionIsVisible = choiceType == "1" && costvalue > 20000000;
    
        Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_under_tolerance").setVisible();
    }

  • Suggested answer
    Ami K Profile Picture
    27 on at
    RE: Hide section based on multiple conditions


    Thank you very much for the quick response! I have a minor change and updated the last part and this is now working.

    function Show_UnderToleranceSection() {
        var choiceType = Xrm.Page.getAttribute("new_businesscasecategory").getValue();
        var costvalue = Xrm.Page.getAttribute("cr37a_costcovered").getValue();  
    
        var sectionIsVisible = choiceType == "1" && costvalue > 20000000;
    
        Xrm.Page.ui.tabs.get("tab_businesscase").sections.get("section_under_tolerance").setVisible(sectionIsVisible);
    }

     

    For anyone who comes across this post - my original code does actually work, there was a mistake on my end with the section name, but this code is far cleaner.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Hide section based on multiple conditions

    Hello,

    If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"

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

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 365 | Integration, Dataverse, and general topics

#1
#ManoVerse Profile Picture

#ManoVerse 101

#2
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans