Rule with run rule with script does not have event.itemName

I have a Rule who should start a script I have in the “Script” section (see image at the bottom).
So I have selected as action “run rules” and selected the script.

But if this is triggered I don’t have the event.itemName available, but if I copy the script in the “execute a given script” inside the rule it is working.

But I need the scripts outside in the “Scripts” section and not inside the rule to reuse the scripts.
So is this a bug or should this really be different?

Working as designed. event represents how the rule was triggered. If you use run rule, that rule isn’t triggered by an event. Therefore there is no event.

If you use a Script Action to run the other rule (a Script is a rule BTW) you can pass properties to the called rule (details differ based on the language of the script action).

OK thanks for the info.
Do I call the rule (script) with


If yes how can I get the param in my called script?

I use the Javascript (ECMAScript 262 Edition 11) for my scripts.

See rules - Documentation.

The args get individually injected into the called rule. For an example from one of my rule templates:

        var data = {};
        data['thingID'] = event.topic.split('/')[2];
        data['thing'] = things.getThing(data['thingID']);
        data['oldStatus'] = parsed[1].status;
        data['oldDetail'] = parsed[1].statusDetail;
        data['newStatus'] = parsed[0].status;
        data['newDetail'] = parsed[0].statusDetail;

        rules.runRule("{{script}}", data, true);

In the called rule, using JS Scripting you’d reference each argument by name:

if(oldStatus == "ONLINE")

It’s different for other rules languages (e.g. Nashorn JS they are available in context if(context.oldStatus == "ONLINE").

1 Like

Thank you very much. It is working now.