[SOLVED] Dynamic item name

I have a rule like this:

rule "FGMS Motion"
when
    Member of fgmsMotion changed
then
    if (triggeringItem.state == ON) {
        switch triggeringItem.name.toString {
             case "fgmsCarportMotion": postUpdate(fgmsCarportMotionDt, new DateTimeType())
             case "fgmsEntreeMotion": postUpdate(fgmsEntreeMotionDt, new DateTimeType())
             case "fgmsHallMotion": postUpdate(fgmsHallMotionDt, new DateTimeType())
        }
    }
end

But i want like this

val motionItemName = "";

rule "FGMS Motion"
when
    Member of fgmsMotion changed
then
    if (triggeringItem.state == ON) {
        motionItemName = triggeringItem.name.toString + "Dt"
        postUpdate(motionItemName, new DateTimeType())
    }
end

Is that possible, now de rule is doing nothing with the last variant?

Yes i have all the items, variant 1 is working…

val lastUpdate = gMotionDt.members.findFirst[ dt | dt.name == triggeringItem.name.toString + "Dt" ] as DateTimeItem
postUpdate(lastUpdate, new DateTimeType())

Yes, did the tric!

Change “val” to “var” (variable) if you want to reassing something to it at later point in your rule.