I doubt that “if exists theTag” does what you think it does. I’d guess that is always true
since you defined theTag
. Would be weird if it didn’t exist after that.
You must check if it is a part of the tags
property of the current record.
Also, setting theTag to the same value every time in the loop is pointless. Do it once outside of the loop.