Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JScript to Show/Hide Sub Grid based on Option Set

(0) ShareShare
ReportReport
Posted on by 175

I have some code written that when the field 'Corporate Tracker Type' = Yes, show the associated Grid, else Hide.  Here is the code I am using:

function ShowHideTTTGrid(context) {

var formContext = context.getFormContext();

var CorporateTrackerType = formContext.getAttribute("lennar_corporatetrackertype").getValue();

var docTab = formContext.ui.tabs.get("{67f21f51-420e-4b0b-ab79-a45d7595ad48}");

if (CorporateTrackerType != true) {

docTab.sections.get('{65e87d15-fb83-4a40-b449-7cf6fdad0706}').setVisible(true);

} else {

docTab.sections.get('{65e87d15-fb83-4a40-b449-7cf6fdad0706}').setVisible(false);

}

}

Does this code look correct?  I am getting the following error:

ReferenceError: Web resource method does not exist: ShowHideTTTGrid
at Dp.execute (lennardev.crm.dynamics.com/.../app.js
at wp._executeIndividualEvent (lennardev.crm.dynamics.com/.../app.js
at wp._executeEventHandler (lennardev.crm.dynamics.com/.../app.js
at Object.execute (lennardev.crm.dynamics.com/.../app.js
at C._executeSyncAction (lennardev.crm.dynamics.com/.../app.js
at C._executeSync (lennardev.crm.dynamics.com/.../app.js
at C.executeAction (lennardev.crm.dynamics.com/.../app.js
at t.dispatch (lennardev.crm.dynamics.com/.../app.js
at Object.dispatch (lennardev.crm.dynamics.com/.../app.js
at Object.dispatch (https://lennardev.crm.dynamics.com/uclient/scripts/app.js?v=1.3.303-1911.4:585:5034)

 In the Form Properties, I have the function Control Form Event OnLoad and Control Corporate Tracker Type Event OnChange.

Thanks for any suggestions!  

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Yep - stupid me. That did the trick. Working as expected.  Thanks again Andrew and rexkenley!

  • Verified answer
    rexkenley Profile Picture
    rexkenley 110 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    You can further simplify by just stating

    docTab.sections.get('{67f21f51-420e-4b0b-ab79-a45d7595ad48}_section_5').setVisible(CorporateTrackerType != 531180000);

    From 4 lines to 1 :)

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Replace line

    if (CorporateTrackerType != 531,180,000) {

    with the line

    if (CorporateTrackerType != 531180000) {

    optionset value is number so no spaces, commas, e.t.c. Value with commas is formatted value.

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Hi Andrew, thanks again for the continual help.  I found what might be an issue.  The field Corporate Tracker Type (lennar_corporatetrackertype) is an option set, not a boolean.  So, I updated the code as such so that the Yes value (when selected the Sub Grid needs to show) is the value 531,180,000.  

    There is no error thrown, however - the Grid (in the Section) does not show at all - it just remains hidden:

    pastedimage1579789153632v1.png

    Here is the updated code:

    function ShowHideGrid(context) {

    var formContext = context.getFormContext();

    var CorporateTrackerType = formContext.getAttribute("lennar_corporatetrackertype").getValue();

    var docTab = formContext.ui.tabs.get("{67f21f51-420e-4b0b-ab79-a45d7595ad48}");

    if (CorporateTrackerType != 531,180,000) {

    docTab.sections.get('{67f21f51-420e-4b0b-ab79-a45d7595ad48}_section_5').setVisible(true);

    } else {

    docTab.sections.get('{67f21f51-420e-4b0b-ab79-a45d7595ad48}_section_5').setVisible(false);

    }

    }

    Do you see anything I am missing?  The Event handlers (onLoad, OnChange) have remained the same.  I do notice that the field Corporate Tracker Type is locked on the form.  

    Ideas?

  • rexkenley Profile Picture
    rexkenley 110 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Sorry, I meant the GUID, that is throwing me off.

    Add this to your code.

    docTab.sections.get().forEach((s) => { console.log(`${s.getName()} ${s.getVisible()}`);});

    This will display all the valid names in your tab.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    It's a bit hard to give you other advises.

    My recommendation - master basics of script troubleshooting. I have a manual for it:

    It's short but it should be enough for you to figure out steps.

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Apologies, I never answered your question.  When I updated the code to include the _section_5, that is when the error stopped.  But the code does not show/hide the section as I expect it to.  Here is the current code:

    function ShowHideGrid(context) {

    var formContext = context.getFormContext();

    var CorporateTrackerType = formContext.getAttribute("lennar_corporatetrackertype").getValue();

    var docTab = formContext.ui.tabs.get("{67f21f51-420e-4b0b-ab79-a45d7595ad48}");

    if (CorporateTrackerType != true) {

    docTab.sections.get('{67f21f51-420e-4b0b-ab79-a45d7595ad48}_section_5').setVisible(true);

    } else {

    docTab.sections.get('{67f21f51-420e-4b0b-ab79-a45d7595ad48}_section_5').setVisible(false);

    }

    }

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    In your scripts you should use the name of tabs and sections. The issue I see comparing your script and screenshot that for section you have _section at the end of the name and I don't see it in the script. Can you post your current code and exact names of Tab and section?

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    Yes, if you look at the code I posted at the top, I am using the Tab Name (not label) and Section name:

    Tab:

    pastedimage1579709488533v2.png

    Section:

    pastedimage1579709461921v1.png

  • rexkenley Profile Picture
    rexkenley 110 on at
    RE: JScript to Show/Hide Sub Grid based on Option Set

    I looked up the documentation and it didn't really say, but aren't you supposed to pass the tab NAME (unless you name your tabs like that).

    docs.microsoft.com/.../formcontext-ui-sections

    community.dynamics.com/.../how-to-write-javascript-code-client-api-reference-formcontext-ui-sections-getparent-setlabel-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

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,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans