How to use a client script "onManual" trigger?

Hello,

How do I trigger an onManual client scripts?

I’ve copied the example in the Generic on click action section of the client automation-scripts docs. Based on the name of the section, it seems to indicate you can press a button to trigger it. But buttons seem to only be able to trigger workflows.

https://docs.cortezaproject.org/corteza-docs/2022.9/integrator-guide/automation/automation-scripts/samples/client-scripts/index.html#_generic_on_click_action

When attempting to trigger via workflow, I get an error

Could not execute automation: unregistered explicit script "/client-scripts/compose/hello-world-client.js.default"

My workflow definition:

Admin view of the scripts available:

Looking at this prior forum post, I understand that workflows only execute server scripts, and not client scripts.

My file structure

extensions/
└── hello-world
    β”œβ”€β”€ client-scripts
    β”‚   └── compose
    β”‚       └── hello-world-client.js
    β”œβ”€β”€ server-scripts
    β”‚   └── hello-world-server.js
    β”œβ”€β”€ package.json
    └── yarn.lock

hello-world-client.js content (taken diirectly from the docs except for the console log):

export default {
    label: "hello-world-client",
    description: "A sample client automation script",

    triggers ({ on }) {
        return on('manual')
            // vv Don't remove the next line vv
            .uiProp('app', 'compose')
    },

    // If you don't need the Compose helper, remove it
    async exec ({ $record }, { Compose }) {
        // Code goes here
        // Note: unless false or an error, the return value is ignored
        console.log("Hello")
    },
}

I aslo tried looking for something other than a workflow that the button can trigger, but as seen in the image below, only workflow are shown.

Any help on getting corredor client scripts to work would be greatly appreciated.
Thank you in advance!

1 Like

Bumping this due to lack of replies

Bumping this again. Is there any full example of client scripts?

Hey, sorry for the delay; I’ll take a look at this in a bit

1 Like

For your concrete case, your trigger definition is missing .for(...)

If you change your trigger to

triggers ({ on }) {
      return on('manual')
        .for('compose:record')
        // vv Don't remove the next line vv
        .uiProp('app', 'compose')
  },

you should be able to see the client-script when configuring the page block

The .for(...) tells the webapp what thing the script is for, which then instructs the interface on how to filter the list.
The β€œwhat thing the script is for” also dictates what arguments the execution receives.

The .for('compose:record'), for example, makes the script for records – available for record pages.
If you want a generic script, you can use .for('compose').

The example you’ve copied – in all honesty, I’m not sure if it was my mistake, worked on an older version, or was meant to be appended to – but we should have it updated and clarified.


Do note that when you’re developing client scripts, you’ll need to refresh your page because client scripts are bundled and served as a bundle to the webapp.

In case the scripts are still not available – restart your containers. When using containerised instances, we’ve noticed the file watchers sometimes fail to pick up changes.
Here is the Corredor env reference.

1 Like

Adding

.for('compose:record')

Did the trick! Thanks a bunch!

1 Like