File-based rule cannot be target of widget's actionrule?

  • Platform information:
    • Hardware: Raspberry Pi 4b
    • OS: OpenHABian 3.4.2
  • Issue of the topic: How to setup a FIFO queue to send commands

I created a widget for entering a username and password for logging into an API. I wanted this widget to pass the values into a rule that would encrypt the password so that it can be safely stored locally. I created a javascript (ECMAScript) file-based rule to be the target of the widget’s actionrule, which passes the entered username and un-encrypted password in the context. The rule reads the passed-in values as such:

var pw = this.ctx[‘widget_password’];

However, whenever I try to submit the widget form, I get an error in the logs:

Failed to execute rule r_encrypt_credentials: TypeError: Cannot read property “widget_password” from undefined: TypeError: Cannot read property “widget_password” from undefined
at execute (credentials.js:12)
at doExecute (webpack://openhab/./node_modules/openhab/rules/rules.js?:242)

However, when I make the exact same rule, with the exact same UID and exact same javascript code (and don’t change anything in my widget), it works fine with no error. So are widgets simply not allowed to target file-based js rules with the actionrule configuration property? Is there an “actionscript” (or something similar) that I would use instead? Or is the rule’s context in a variable other than this.ctx?

Note that unless you are careful this password can end up in the logs.

I assume you are not using Nashorn JS. That’s the Nashorn JS syntax. For GraalVM it’s just var pw = widget_password;. Nothing fancy. It’s just there.

I never tried this with file based rules. It might be the case that the way the execute function is set up and configured that it doesn’t get anything except the event passed into it. I don’t use file based rules so I don’t have any knowledge to draw on here. @florian-h05, I hate to tag you but is this another spot where file based and UI based rules are different? Are the passed in values even available? If not I think it should be. I can file an issue if it needed.