That looks like Rules DSL.
Here’s the problem. The term “Script” is overloaded in OH and it’s confusing.
One can write a .script file and place it into the $OH_CONF/scripts folder. Then one can use the callScript() in one of your rules. I think the code above will work as written as a .script file. But there are limitations as you cannot pass data to a .script nor can you receive a value back from a .script.
One can write a shell script and call that from openHAB using
executeCommandLine or the Exec binding.
In a rule, one can create Script Actions and Script Conditions which have the code to execute when the rule triggers.
In MainUI there is a Scripts section. This has a special type of rule which consists only of a single Script Action. But it’s still a rule like any other.
You’ve created that last one. So to call it from another rule you have a couple of options.
In MainUI, in your rule you can choose “Run Script” as the action and select your Script from the list.
// Run another rule
var FrameworkUtil = Java.type("org.osgi.framework.FrameworkUtil");
var _bundle = FrameworkUtil.getBundle(scriptExtension.class);
var bundle_context = _bundle.getBundleContext()
var classname = "org.openhab.core.automation.RuleManager"
var RuleManager_Ref = bundle_context.getServiceReference(classname);
var RuleManager = bundle_context.getService(RuleManager_Ref);
var map = new java.util.HashMap();
map.put("test_data", "Passed data to called function!")
RuleManager.runNow("tocall", true, map); // second argument is whether to consider the conditions, third is a Map<String, Object> (way to pass data)
To access the map in the called rule:
Also be aware that in the other languages you can put the code into a library and import that into your rule as another alternative to calling another script.