DEV Community

Cover image for PACX ⁓ WebResource Management Commands - Create JS
Riccardo Gregori
Riccardo Gregori

Posted on

PACX ⁓ WebResource Management Commands - Create JS

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.

Default templates

To create a JS WebResource for a form you can use:

pacx wr js create --for Form --table Account
Enter fullscreen mode Exit fullscreen mode

To create a JS WebResource for a specific table ribbon, you can use:

pacx wr js create --for Ribbon --table Account
Enter fullscreen mode Exit fullscreen mode

To create a JS WebResource for a global ribbon, you can use:

pacx wr js create --for Ribbon
Enter fullscreen mode Exit fullscreen mode

To create a generic JS WebResource, you can use:

pacx wr js create --for Ribbon
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more