Wrong function description in runRule()

Hi there

I’m struggling with the function runRule() which comes with the new javaScript EMCA 2021 engine. I found a wrong declaration in the documentation, please check:
https://openhab.github.io/openhab-js/rules.html#.runRule
According some research the function should be:
RuleManager.runNow(“service_status”,true,data);

Cheers Nicolas

What specifically are you struggling with?

That documentation is for the openhab-js library. The openhab-js library implements a runRule() function in the rules namespace. As you can see from the implementation of that function:

/**
 * Runs the rule with the given UID. Throws errors when the rule doesn't exist
 * or is unable to run (e.g. it's disabled).
 * 
 * @memberOf rules
 * @param {String} uid the UID of the rule to run
 * @param {Map<Object>} [args={}] args optional dict of data to pass to the called rule
 * @param {Boolean} [cond=true] when true, the called rule will only run if it's conditions are met
 * @throws Will throw an error if the rule does not exist or is not initialized.
 */
 const runRule = function (uid, args = {}, cond = true) {
    const status = RuleManager.getStatus(uid);
    if(!status) {
        throw Error('There is no rule with UID ' + uid);
    }
    if(status.toString() == 'UNINITIALIZED') {
        throw Error('Rule ' + uid + ' is UNINITIALIZED');
    }
    RuleManager.runNow(uid, cond, args);
};

The documentation is correct.

If you want to use RuleManager yourself without the additional checks implemented by this rule then you can. But the documentation for rules.runRule() is correct.

Now, it might be the case that the runRule() function has not found its way to the binding. Are you running the snapshots? If so you might have to install the latest version of the openhab-js library using npm. If you are not running the snapshots, you should refer to the docs for your specific version of OH, not the latest.

Hi Rosko,
Thanks for your fast assistance. The function was not callable in my case, but I also do have similar problems with other functions of the openhab-js library.
I solved it by calling them in the beginig of the rules similar as the procedere in the JS-Nashorn libary.
My setup has the release 3.2. Is there a known issue with the namespace of the openhab-js library? If yes, what’s the workaround?
I assume this ticket can be closed.-)

Sort of. runRule wasn’t implemented until after the 3.2 release. If you want to use new stuff, you have to upgrade to a verison of the software that actually implements the new stuff.

The work around would be to install the latest version of the library using npm. But if you do that, keeping the library up to date becomes your responsibility. Updating OH will not update the library as long as you’ve it installed via npm.
.