Call a script function from a script?

Hallo,

I have an Raspberry with OH 3.2

I have a test switch named “test” and a test number item named “test_number”
Every time I toggle the switch, the item “test_numer” add 1.

So I have a rule named “test” (with UI) that start a script:

events.sendCommand('test_number', og_sz_status("fenster"));

And I have additional create a script with UI (named heizung_og_sz_status) with this code

function og_sz_satus(event) {
  if (event == "fenster") {
    var item = itemRegistry.getItem('test_number');
	return item.getState()+1;
  }
}

But it does not work!

Have anybody a hint?
Regards
Michael

I would be helpful, if you logged out some information.
I guess the culprit is either

or

If item.getState()+1; works then probably a Number is returned. However sendCommand requires a string

[quote=“MM10, post:1, topic:130883”]
item.getState()+1;
[/quote

If I put the code in the script, which I called in the rule …

var item = itemRegistry.getItem('test_number');
events.sendCommand('test_number', item.getState()+1);

… it works fine.

I think the problem is the call from the javascript function. But I don’t know, how is the correct syntax to call a javascript function in OH3.

That’s not good Scripts work. A Script in the UI is just a special kind of rule that consists of only a single Script Action. It’s not a library you can import and use in other rules.

For that see OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules which will work for both Nashorn and JSScripting, though they’re are better ways to do it in JSScripting but I’ve but had a chance to write a tutorial yet