Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Trying to hide sections on a form based on a field value

(0) ShareShare
ReportReport
Posted on by

I am trying to show and hide sections on a form based on a field value (currency field type). This does not appear to be working and all sections always show regardless of field value. I have added this to the form properties for onload and onsave and on the amount requested field for onchange. The default for each section is visible. (I added the alerts to see if it was working but nothing is being shown in the alert either) 

// JavaScript source code


//Show/hide approval sections on CER form based on Amount Requested Value

function showHideApprovalSections() {
//get field value

var AmountRequested = Xrm.Page.data.entity.attributes.get("msft_amountrequested").getValue();
{
if (AmountRequested < 1,000,000)

//hide sections based on value
{
Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);


// Display an alert box
alert("AmountRequested");

}
else if (AmountRequested < 100,000)
{
Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);
alert("Amount < $100K");
}

else if (AmountRequested < 15,000)
{
Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(false);
Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);
alert("Amount < $15K");
}

}
}

*This post is locked for comments

  • RE: Trying to hide sections on a form based on a field value

    Hi nemsley,

    Any luck? Has it started to work properly?

    Thank you.

    Kate

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Trying to hide sections on a form based on a field value

    Hi,

    Remove the commas in between the numbers as shown below.

    AmountRequested < 1000000

    AmountRequested < 100000 

    AmountRequested < 15000

    Try the modified code below.

    // JavaScript source code
    
    //Show/hide approval sections on CER form based on Amount Requested Value
    function showHideApprovalSections() {
    //get field value
    var AmountRequested = Xrm.Page.data.entity.attributes.get("msft_amountrequested").getValue();
    {
    if (AmountRequested < 1000000)
    //hide sections based on value
    {
    Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);
    
    // Display an alert box
    alert("AmountRequested");
    }
    else if (AmountRequested < 100000)
    {
    Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);
    alert("Amount < $100K");
    }
    else if (AmountRequested < 15000)
    {
    Xrm.Page.ui.tabs.get("approvals").section.get("ceo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("cfo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("coo").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("eng").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("bgsrmgr").setVisible(false);
    Xrm.Page.ui.tabs.get("approvals").section.get("facilitygm").setVisible(true);
    Xrm.Page.ui.tabs.get("approvals").section.get("srfinance").setVisible(true);
    alert("Amount < $15K");
    }
    }
    }

    Hope this helps.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Trying to hide sections on a form based on a field value

    To add to Andrii's answer(which is what you should do anyway).. You should also change the order of those if-s. Otherwise, your code will hit the first if and will never get to the second or third.

    Should be

    if(AmountRequested < 15000)

    {

    }

    else if(AmountRequested < 100000)

    {

    }

    else if(AmountRequested < 100000)

    {

    }

  • Verified answer
    RE: Trying to hide sections on a form based on a field value

    Instead of looking through your code. I think this is something you need to learn to debug your javascrips.

    Press F12 in your browser that will open the developer tools (whatever you call that), and start searching for your scripts and putting the breakpoints to step through each line.

    There are plenty of online tutorial guiding you how to use that.

    msdn.microsoft.com/.../gg589507(v=vs.85).aspx

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Trying to hide sections on a form based on a field value

    Hello,

    Try to use

    if (AmountRequested < 1000000)

    instead of if (AmountRequested < 1,000,000)

    and do the same way for all other if..then statements.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans