Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide section based on multiple conditions

(0) ShareShare
ReportReport
Posted on by 25

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
    }
}

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 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?"

  • Suggested answer
    Ami K Profile Picture
    Ami K 25 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.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 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();
    }

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! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans