OH3 - DSL Rule - 'state' not working on an item as string

I try to get the state from an item in a DSL Rule:

var String intentItem = transform("JSONPATH", "$.slots[0].value.value", ChangeLightState_ChangeLightState.state.toString)

intentItem.sendCommand("ON") //works
var state = intentItem.state.toString //does not work

So I get the name of the item via MQTT.
Then I can change the state via sendCommand but I am not able to get the state. I get the following error: The method or field state is undefined for the type String
(I would assume the same error for sendCommand)

What am I doing wrong?

That’s plain enough, intentItem is just a string and has no .state method.

Second time I’ve seen the claim that works recently, it shouldn’t.

If you’ve got an Item name in a string, you can access the Item using scriptServiceUtils

Thanks

I already had a look on ScriptServiceUtil but while adding the ‘import’ it complains that import is undefined. It is like it is not supported in DSL Rules.

Do I need to install something or do I need other configs in order to use import statements in DSL Rules?

See

It’s UI rules you cannot use imports in, not DSL in general.

@rossko57 Thank you very much! =)

For others to see a working example in DSL Rule GUI:

var String intentItemString = transform("JSONPATH", "$.slots[0].value.value", ChangeLightState_ChangeLightState.state.toString)
val intentItem = org.openhab.core.model.script.ScriptServiceUtil.getItemRegistry.getItem(intentItemString)


var state = intentItem.state.toString //works

I already had a look on Script Service Util but while adding the ‘import’ it complains that import is undefined. It is like it is not supported in DSL Rules. Tellpizzahut

There are multiple openHAB versions in common use. This affects where you have to get imports from. Which are you using?
There are file based DSL rules, and UI based DSL rules. These behave differently so far as imports goes. Which are you using?