OH3.2: use ECMAScript-2021 as action for oh-button

I’m using the latest Javascript ECMAScript-2021 and have written a JavaScript in automation/js.
In my UI, I have added an oh-button and want to run my JavaScript located in automation/js but it is not shown in the scripts list.
I’m facing the same issue if I try to create a rule by using the web UI: the script is not found.
Do you have any idea how to start such a script from a button?

Thanks for your help

It wouldn’t show up there. A Script is a rule consisting of a single Script Action (no triggers, no conditions) and has the “Script” tag. I’m not certain it’s even possible to create a “Script” from a .js file.

Your rule should show up under Rules.

Again, it probably shows up under Rules. If it doesn’t show up anywhere there is something else wrong.

Yes, create a rule that is triggered by commands on an Item used by the oh-button widget.

Or look under Rules to find the UID for the rule (it’ll be some random text unless you specify it) and enter that UID as the rule to run for the “rule action” on the oh-button widget.

The arrow is pointing to the UID of this particular rule.

I tried to create a rule without a trigger as it is started as a “rule action” by the oh-button,

'use strict';

    name: "plc_pool_write_prog1",
    description: "Write PLC Pool Prog1 data on setpoint change",
    triggers: [],
    execute: data => {
        console.debug("#################### PLC Pool Prog 1 setpoints have been updated");

but I get the following error while the rule is loaded:

10:24:43.504 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab/automation/js/test.js’: org.graalvm.polyglot.PolyglotException: TypeError: ruleConfig.getEventTrigger is not a function

I also tried to remove the triggers line but I get the same error.

Any idea?

As I said

I’m not certain it’s even possible to create a “Script” from a .js file.

Not having a trigger is insufficient. You also need to apply the “Script” tag. And it appears that you can’t create a rule without a trigger using the library anyway.