Trigger formula circular reference

Hi there !

I’m trying to write a trigger formula thats sets a datetime cell with the highest value (which is the latest date) contained in its own column. The goal is to have new records stay at the bottom until told otherwise, as this widget is ordered by date.

Obviously that screams circular reference, and i cannot get out of this hellish loop. Could you give me a hand on that ? I tried various hacks and formulas but nothing got me out…

Thanks !

Hey @Enthouane !

When are you wanting this trigger formula to be triggered? If its triggering when a new record is created, you could use the formula NOW() which records the current DateTime value. Then, when ordered by Date, newest records would always be at the bottom. Using NOW() would make it specific enough that when you have multiple records for the same date, they’d still be ordered by creation time.

Re-reading your note again - if you want to look at all values in this column (for all records), you might be able to use the PEEK() function to do that.

I’m not very sure what you’re trying to do here so if these suggestions are not helpful, please feel free to respond with screenshots and I can hopefully offer some better suggestions!

Thanks,
Natalie

In your trigger formula, you’re going to want to use the grist UserTable.all function Function reference - Grist Help Center to get all records from your table, then use dot notation to limit to your datetime column which will give you a python list of the datetime values, then find the largest value in that list, and return that value.

To me, that’s what it sounds like you’re trying to do.

Hi and thanks for your thorough reply ! To be more precise, i’m trying to trigger this formula for each new record, in order to keep that newly created record at the bottom of the table. This is purely for row editing convenience as it keeps this new record at the last line as the table is sorted by this particular datetime column.

As i’m typing that i realize that my workflow might not be optimal and i’ll rethink it to bypass this need. But i’m still curious so i’ll check the peek() function. I fear that when asking a trigger formula to read and sort all records of its own column i might still get a circular reference error.


That’s exactly it. I’ve tried MAX(table.all.datecolumn) as a new record trigger formula for $datecolumn, among many many other formulas but none ever got me out of the circular reference error.