In this post I subtly introduced a few PACX commands created to streamline WebResource development lifecycle.
On the previous one we've seen how I like to setup my WebResource project.
Now let's deep dive on creating JS Web Resources to be bound to Forms or Ribbon (command bar) commands.
📃 pacx webresources js create
This command has a few aliases pacx webresources js create
, pacx wr js create
, pacx wr create js
. It can be used to create a JS file that can be used in:
- forms
- command bar for a given table
- global command bar
...or generic utility files, starting from a predefined, fixed template.
The default templates for each type of JS WebResource are described here.
To create a JS WebResource for a form you can use:
pacx wr js create --for Form --table Account
To create a JS WebResource for a specific table ribbon, you can use:
pacx wr js create --for Ribbon --table Account
To create a JS WebResource for a global ribbon, you can use:
pacx wr js create --for Ribbon
To create a generic JS WebResource, you can use:
pacx wr js create --for Ribbon
When creating JS WebResources for Dataverse, is a best practice to enclose the classes and function definitions in namespaces to avoid collisions with out of the box stuff, or classes / functions defined by other customizers. The predefined template for each type of JS WebResource described above accepts the --namespace
as input argument. If not provided, the publisher prefix of the publisher of the default solution for the environment is used (unless you specify a different solution via --solution
argument).
👨🏻💻 I don't like the default template. Can I change it?
Sure you can! Via pacx webresources js setTemplate
command you can update the default templates. E.g.
pacx wr js setTemplate --type Form --file myCustomFormTemplate.js
pacx wr js setTemplate --type Ribbon --file myCustomGlobalRibbonTemplate.js
pacx wr js setTemplate --type Ribbon --forTable --file myCustomTableRibbonTemplate.js
pacx wr js setTemplate --type Other --file myGenericTemplate.js
In custom templates you can use %NAMESPACE% and %TABLE% as placeholders where to put the namespace and the name of the table passed as inputs to pacx wr js create
command.
👨🏻💻 Nice! Now that I've changed the default templates, I liked more the original ones. Can I rollback to the default?
Of course you can, via pacx webresources js resetTemplate
pacx wr js resetTemplate --type Form
pacx wr js resetTemplate --type Ribbon
pacx wr js resetTemplate --type Ribbon --forTable
pacx wr js resetTemplate --type Other
It will restore the default template, overwriting your changes.
🏃🏻 What's next?
In the next article of this series we'll see how to push WebResources to Dataverse with minimum effort.
Top comments (0)