How it works...

In the first three steps, we created our JavaScript function. Notice how we introduced a namespace at the beginning of the file. JavaScript namespaces are a good practice when creating enterprise applications. Namespaces will ensure that different libraries with the same function names can coexist, and that your code calls the correct method. Furthermore, the way we declared the namespace, which is shown in the following line of code, ensures that if the namespace is already declared in a different file, the content does not get overridden:

var packtNs = packtNs || {}  

This practice is particularly important when you refactor your large JavaScript library into a collection of files.

Notice the conventional JsDoc comments: /** */. JsDoc is the standard documentation style for JavaScript. Visual Studio autogenerates the skeleton of your comments when you start typing /**. In the remaining recipes of this book, we will omit the comments to make our code more concise.

In step 5 and step 6, we added the JavaScript library to the form to ensure it is loaded when the form is loaded.

In step 7 to step 9, we manually wired the function to trigger during the OnChange event of the Post Graduate Start Date field.

In step 10, we saved and published the changes. The publishing step is important to reflect your changes on the instance. Until the Publish button is pressed, your changes will not be available for use.

The function itself looks at the content of the hardcoded fields, Supervisor and Post Graduate Start Date, and sets the value of Post Graduate Start Date to today's date if the Supervisor field is not null and the Post Graduate Start Date field is null.

Behind the scenes, Dynamics 365 saves your web resources in its database and loads the necessary resources when the form is loaded, as if they are a part of the web application content. It then calls the populateWithTodaysDate function when the value of the Supervisor field is changed.

As a first simple JavaScript function, it is straightforward; however, when building enterprise applications, try to avoid hardcoded values and consider maximizing the reuse of your functions by making them generic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.103.210