Check if Item exists and Check if there is transformation

Hello,

is anyone knows how to check if:

  1. item exists.
    I use the rule
    val SocketItem = ScriptServiceUtil.getItemRegistry.getItem(transform("MAP", "broadlink.map", receivedCommand.toString))

But item not in registry i get

2020-01-13 21:24:43.982 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Change Item State from real Remote Controller': Item '' could not be found in the item registry

  1. transformation returns result. Again the same code i get sometimes error is there is no transformation
2020-01-13 21:24:43.978 [WARN ] [rm.AbstractFileTransformationService] - Could not transform 'ID-0171f400--SWITCH-2--CMD-OFF' with the file 'broadlink.map' : Target value not found in map for 'ID-0171f400--SWITCH-2--CMD-OFF'

Thanks a lot!

I know that i can put in broadlink.map something like

=noBroadlinkItemValue

and then check it. But it is interesting if there is a way to check item and transformation

  1. I don’t know of a way in Rules DSL. You might be able to put the call to getItemRegistry into a try/catch and catch the exception when it doesn’t exist.

I Scripted Automation it’s pretty easy and you have lots of ways. I’d probably use (Python)

if "ItemName" in items:
  1. It there is no entry in the map file for that value you will get an error from the transformation. Again, you might be able to put the transform into a try/catch.

But one wonders why you are using the map. Perhaps there is a way to generate the Item name from the message directly (e.g. strip off the stuff at the end?).

1 Like

Similar question asked and answered here…

You might want to put the transform value into a variable first. Or as Rich suggested, use a try/catch.