Adding a field (last update) to changeset

Hi, I know it's possible to do but i'm not sure how ! I want to update an additionnal column when my query triggers. So users make change in the table and when they save this query triggers :
image
there is a field named LastUpdate and when this query triggers I want to change the LastUpdate value for all rows in the changeset to be the date and time right now.

I saw someone posting this but i'm not sure how to apply it to my query :slightly_frowning_face:
{{ myArray.map(element => { return {...element , myProperty: newValue} } ) }}

Hi @brocantcode,

It looks like the code you have shown above is pretty close. It really depends on what the LastUpdate value is in your data. For example, if it's just a text string, you could put this in your "Array of records to update"

{{ tableInventory.chagesetarray.map( c => { return {...c, LastUpdate: Date() } } ) }}

That will write the date as a string, Tue May 28 2024 14:58:59 GMT-0400 (Eastern Daylight Time) into the LastUpdate field.

Retool also has access to MomentJS which can do a lot of date field manipulation. You can see the docs here.

Hi, it is date field
image
When I try the code it says that it cannot read map
image

Try using changesetArray instead; the properties are case sensitive.

Oh wow didn't see that :sweat_smile:

The query does not work it throws an error
image

In your table is the option to send the full row of data turned on?

image

I think (even though you'd think it would know based on the primary key column selection) it needs to see the data in full row.

I ask because it says that the id property is undefined but I'm not sure if that is from the row or the trigger.

it does not like the moment({})
But it does not like Date() either

The format in my table is like this :
LastUpdate "2024-05-28T19:14:22.839Z"
and Date() return this :
invalid input syntax for type timestamp with time zone: "Tue May 28 2024 16:22:20 GMT-0400 (heure d’été de l’Est nord-américain)"

So i need to match the Date()

I used new Date() and now it is working !

So no need to Includes all rows.
Just using this worked
{{ tableInventory.changesetArray.map(c => { return {...c, LastUpdate: new Date() } })}}

Thank you @pyrrho and @MikeCB

3 Likes