[Solved] How to implement a Designer global external function?

Le’ts say we have some business logic shared among dozens of datamappers and templates.

How could we proceed to avoid embedding such scripts in each datamapper\template?

The ideal approach would be to define scripts in a shared directory and have the datamapper and template load them at runtime.

A practical example is a REST API that the Designer have to query to retrieve data to use in the datamapper and the template.
If for any reason we change the API schema we would have to manually go in each datamapper and template to reflect the changes, on the other hand, if we have the logic in files outside the connect resources we can apply the update in one single point.

On the other hand defining a REST client outside the scope of Designer could allow defining it once and for all.

Hi Maxiride,

I typically use a Workflow/Automate process to act as an proxy to retrieve images and content that are behind protected endpoints in CMS/ECM systems. So my scripts in the templates are agnostic to the environment and all use the same endpoint (and credentials) setup in the Workflow/Automate process. It is the process/flow that retrieves the respective content.

For script files this is currently handled through eval() as explained in the post, which you already found:

When in need in handling an arbitrary number of files I would combine these files using a tool like Minify in Visual Studio Code. This VSC extension can minify js (and css) files but is also able to combine all files in a folder (leaving your original files untouched).

I’ll bump the remote Control Script ticket on our backlog.

Erik

image

image

Thanks for the feedback! Minifying and merging all the JavaScript snippets could be viable so that we can use a single loadtext eval() in each template.

Anyway as mentioned in the other thread this method applies only to templates, in the datamapper we don’t have a load eval function.

For future reference, as suggested we also added a datamapper runtime property APIEndpoint which is passed down by the call to the datamapper so that the HTTPRequest object is created with a variable instead of an hard coded URI.