Skip to content

Shared Script Deployment

James Novak edited this page Mar 31, 2019 · 4 revisions

Web Templates

Shared script libraries can be saved as Web Templates and made available to Web Pages, Web Forms, and Entity Forms using Liquid. For an overview on this method of Dynamics Portals Script Management, please review the following post: Dynamics Portals Script Management

Each shared script module to be referenced should be added to its own Web Template with a unique name. For example:

Script - Common Utilities - Web Template.ts

can be deployed as a new Web Template with the name: Script - Common Utilities

Including Shared Scripts

Once deployed as a Web Template, the content of the script can be referenced using the Liquid Include statement. For example, to reference the Common Utilities from above in an Entity Form, the following line should be included in the Entity Form script block:

{% include 'Script - Common Utilities' %}

When the Entity Form renders, the contents of the 'Script - Common Utilities' will be injected into the page and any script will be available to subsequent scripts within your web page. This adds some overhead to the Entity Form, but it removes the need for an external resource to be downloaded by the browser.

This include method can be used for any additional Web Template scripts required for your situation.

Using Referenced Scripts

Included in the project is a sample script, Script - Validator Samples - Web Template.ts. This is an example of using the Validator scripts injected using the include method. Below is an abbreviated version of the generated JS for this TypeScript sample.

{% include 'Script - Common Utilities' %} {% include 'Script - UI Utilities' %} {% include 'Script - Validators' %}

$(document).ready(function () { var name = $("#futz_name").val(); if (Common.utilities.isNullUndefinedEmpty(name)) { $("#futz_name").val("New Sample Validator Item!"); } Common.validators.addLinkedNullValidator(new Common.triggerControl("futz_linkedcheckbox", "check", true), "futz_linkedtextboxcheckbox", "Please enter a value for the 'Linked Text Box - Checkbox'", true); Common.validators.addFutureDateValidator("futz_nofuturedate"); Common.validators.addMaxDateValidator("futz_maxdatevalue", new Date("10/10/2020")); Common.validators.addDateRangeValidator("futz_daterangevalue", new Date("10/10/2015"), new Date("10/10/2025")); });

Clone this wiki locally