[Solved]Variable declaration in conditional statement

Hello everyone,

I am a beginner in groovy, I am trying to write a script that detects the type of the event that triggers it, I have two:

  • A channel trigger
  • An item state change

I want my script to create a string variable to be used later in each case.

I make this test script to just print out the string i create in the if statement but i get an error that this variable does not exist.

did I do something wrong in declaring the variable? is there a scope issue?

NOTE: if I move the logger.info(str) inside the conditional expression, everything works fine!


Since you need this variable in “each case” after the if statement I’d declare it upfront (i.e. before the if statement).

@opus Thank you! it worked

Cheers!