Adventures with Model-Driven Apps: Toggle Element Visibility Based on Dataverse Status Column

I wanted to see if I could toggle visibility for a Tab and/or a Section on a Form, whenever an Account record was Activated or Deactivated.

Figure 1 – Tab and Section to toggle visibility on for an Account

First thing I did was make sure the names of my Tabs and Sections were unique.

Figure 2 – Unique names

I made the following changes in my form:

  • Set the Name for the Summary tab to TAB_SUMMARY.
  • Set the Name for the Contacts tab to TAB_CONTACTS.
  • Set the Name for the Contacts section on the Summary tab to SECTION_CONTACTS_TAB_SUMMARY.

Now for a little JavaScript to make the magic happen. 🪄

I created a JavaScript file called AccountFormEvents.js.

I uploaded it as a Web Resource in my Solution.

Figure 3 – Upload JavaScript file as a Web Resource

Back to my Form!

I updated the Events for both form On Save and On Load, setting the Library to the Web Resource I just created, and setting the Function to AccountFormEvents.formOnSave and AccountFormEvents.formOnLoad, respectively.

Figure 4 – Adding On Save and On Load events

The one thing I had to do to get this working, was add the Status field to the Form.

If I didn’t do this then I wasn’t able to respond to the change of the value, having the Status field on the Form allowed me to do so.

I went ahead and marked the Status field as hidden. 🙈

Figure 5 – Add Status field and mark it hidden

One last thing I needed to do was wire up the On Change event for the Status field.

I used the same JavaScript Web Resource from the previous step and set Function to AccountFormEvents.attributeOnChange and checked Pass execution context as first parameter.

Figure 6 – Configure event for the Status field

I then clicked Save and publish.

Figure 7 – Testing my form

I fired up my Model-Driven App that includes the Form and tested clicking Activate and Deactivate.

When the Status is Active, the Tab and Section are Visible. 👀

When the Status is Inactive, the Tab and Section are Hidden.

Download the complete solution at https://mattruma.com/wp-content/uploads/2024/03/ModelDrivenAppSolutionHideSectionOnInactive_1_0_0_0.zip.


Discover more from Matt Ruma

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *