
First up, it is really really frustrating that you can't refer to the standard Name column in a Calculated type column!! Bizarre. So I'm now having to jump through hoops to create a secondary column, let's say `Name Tracker`, and create a flow which triggers off any change to the Name, and updating `Name Tracker` with the new value... just to keep a duplicate copy of Name that I can actually use in my Calculated column!
I'm using the "When a file is created or modified (properties only)" trigger, and updating `Name Tracker` with the latest version of `Name`... but am really struggling to prevent an infinite loop. I've tried looking for changed properties (after trigger) but that isn't working. Plus, I'd rather not trigger and then abort... I'd rather not trigger at all... hence my preference is to use a trigger condition.
So I created another custom column `PrevName`, and in the trigger condition I'm trying:
@Anonymous(equals(triggerBody()?['Name'], triggerBody()?['PrevName']))
And then if it proceeds, I set PrevName to Name, so that it shouldn't trigger next time (unless Name has changed).
But this doesn't seem to work... it just keeps re-triggering over and over.
This is really like pulling teeth... all to solve a problem that shouldn't be a problem in the first place!
UPDATE sometimes it doesn't seem to trigger at all... except when I save the flow... I can't understand why saving a flow (not making any changes to the file itself) would trigger anything?!
OK I'm answering my own question, and also sharing a tip to anyone other relative newbie tearing their hair out over trigger conditions.
Firstly, top tip for debugging trigger conditions is NOT to start with the expression in the trigger condition itself, but as an expression in a Variable action later in the flow. That way, you're seeing all triggers happen and not left wondering whether the flow hasn't triggered because of the trigger itself, or maybe a buggy trigger condition, or maybe just because the triggering has been delayed (sometimes it takes a while in the system I'm working in).
Another top tip is to add a Compose step set to the expression:
triggerBody()
That way, when the flow triggers, you can go to the Compose step and see exactly what data is available from the trigger body, what the names are, and what the values are.
From this process I discovered that I shouldn't be querying 'Name' from the body, but rather '{Name}' i.e. with curly brackets. This is apparent from the output from the Compose step. Or if you need the name with extension, it's '{FilenameWithExtension}'.
So, I was close before, but not close enough. The correct expression for the trigger condition is:
@Anonymous(equals(triggerBody()?['{Name}'], triggerBody()?['PrevName']))