Adventures with Power Platform: Model-Driven Apps and JavaScript

If you are a Citizen Developer, don’t let the title of this article discourage you!

We are going to look at some code, but not terribly difficult code! It is code you could write or have a traditional developer write for you.

A customer was migrating and Access database and was asking how to mimic some functionality that was in their Access database in the Power Platform.

Figure 1 – Model-Driven App Screen

I have a Model-Driven App that allows editing of Dataverse Table with the following fields:

  • Combo217 – Choice, Values 0-6
  • Text120 – Date, Date Only
  • Text115 – Choice, Yes/No

When the value of Combo217 or Text120 changed, the value of Text115 would be set to Yes or No based on the values in Combo217 and Text120.

As the values changes, the Model-Driven App needed to update immediately.

I tried doing this with Business Rules, but there was a calculation that needed to occur around elapsed days between two dates.

I tried to create a column in the Dataverse table for Elapsed Days using a Formula column, but Power FX support is limited.

A teammate showed me how to do it with a workflow process, but that was going to be challenging for the customer, not very friendly.

Also, some of this functionality would only run for existing records.

What could I do now? I could write some JavaScript.

Wasn’t has bad as I thought, kept the names of the field the same, just to make it easy.

I followed the article at Configure event handlers for model-driven app Main forms in Power Apps – Power Apps | Microsoft Learn to configure my JavaScript to run in my Model-Driven app.

Figure 2 – Adding JavaScript support to Model-Driven App

I saved and published all the changes, and what do you know? It all worked perfectly!

Testing was a bit challenging, as I had to keep uploading any fixes, publish the changes again and then test.

But all in all, a viable solution.

Check it our for yourself by install the solution at Sample2Solution_1_0_0_0.zip into your Power Platform environment.

As always, if there is a better way, please share!


Discover more from Matt Ruma

Subscribe to get the latest posts to your email.

Leave a Reply

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