BACK
|Dynamics 365 (CRM)

My Take On Writing Entity JavaScript Forms

This is a subject that could garner a lot of controversy, as with all things, there are different opinions for what constitutes best practice. So I'm going to preface this one by saying that this is what I've found to work the best for me in my experience consulting.

We have all no doubt seen some absolute shockers when it comes to how these have been laid out in the past, so here is my code neat freak take on it.

Entity JavaScript. Love it or hate it, you're going to come across this in the power platform. So get cosy.

If the entity doesn't have an existing JavaScript file. This is how I'll go about creating the file.

From there. Its as simple as registering those two functions onSave & onLoad in our form event handlers.

Obviously repeating this for our onSave function too.

My reasoning for this approach is as follows.

  1. You're only registering two functions on the form itself. Eliminating the need to look through each field for an onSave, onLoad or onChange binding.
  2. We're hoisting up our executionContext and formContext into our global variables for use in debugging if you don't have access to those contexts yet. Not always needed, but handy to have if you do (If you're unfamiliar with variable hoisting this link might help you).

© Copyright 2021 All rights reserved.