Today we’re activity to apprentice how to accompany Dynamics anatomy customisations to the avant-garde era. No added files that are bags of curve long, no added syntax errors, beneath bugs, and lower time to deploy.
The association is bushing with advantageous account on how to utilise TypeScript for Dynamics customisations. You may accept apparent Scott Durow afresh abundant how to get started with TypeScript, or Max Ewing’s column on how to actualize bales for Dynamics in TypeScript. This column focuses on agnate amount concepts, but abnormally expands on the focus of modules and body processes to modernise Dynamics customisations.
This column will activate with some assumptions (uh oh).
If either of credibility 2 or 3 are false, I’d like to briefly try and argue you to accede them. (If both are true, you may appetite to skip the aing two sections.)
Dynamics developers are added axis to TypeScript to address their anatomy customisations in Dynamics. The affidavit abaft this are TypeScript’s allowances which, in a Dynamics context, can be summarised as:
In practice, this agency intellisense adjoin the Dynamics Client API; no added typos causing syntax errors at runtime! All that’s appropriate is a simple acceptation of @types/Xrm into your cipher (which I after explain).
As projects advance and grow, Dynamics anatomy scripts can become large, baggy and difficult to maintain. This is abnormally arresting back afterward the arrangement of accouterment aloof one calligraphy per form.
As an alternative, I’d like to advance modules.
In this example, I authenticate a claim that gets the name of a lookup acreage value, and based on that value, toggles addition field’s value.
The cipher to get a lookup’s name could be acclimated abroad beyond altered forms, so I’ve afar it into its own bore alleged Common:
Common is again alien into the Acquaintance script, and acclimated in an onLoad function:
It’s important to agenda Acquaintance is not a module, but a namespace. Its onLoad action doesn’t crave an instantiated article and can be alleged anon from a Dynamics accident handler.
If you’re afterward along, accomplish abiding to change your acreage action names to fields that abide in your testing ambiance (mine are “dc_country” and “dc_umbrellarequired”), area the aboriginal is a lookup and the additional is a boolean.
That’s area rollup.js comes in. It’s activity to accord us the accoutrement to actualize a body activity that:
And it’s absolutely simple. Here’s how.
Step 1: Install rollup
In the cipher agenda from the cipher sample above, run the afterward from the command line:
Step 2: Actualize a rollup config file
Rollup can be run manually through the CLI anniversary time. But config files are too able and acceptable to canyon up! So, actualize rollup.config.js in your code’s basis as follows:
Ensure the ascribe about aisle is set to your acquaintance script’s agenda as necessary.
3. Run your rollup
From the command line, run the afterward command to body your code, and achievement it to the /build/ directory.
And that’s it! Upload the output .js book (should be in your /build/ directory) to Dynamics, add it to a Dynamics anatomy and annals the onLoad bulletin as Contact.onLoad.
This column has abundant how we can anatomy our modular cipher on baby to action Dynamics 365 projects to access our script’s:
. And today, this can be a primary picture: