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](https://community.retool.com/uploads/default/original/3X/7/2/72ecf8ec8b0604342ab75b6321da9be4de3d9bf3.png)
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: :slightly_frowning_face:](https://community.retool.com/images/emoji/apple/slightly_frowning_face.png?v=12)
{{ 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](https://community.retool.com/uploads/default/original/3X/c/7/c7820f95441b86037d5d70d0fafb49e109487627.png)
When I try the code it says that it cannot read map
![image](https://community.retool.com/uploads/default/original/3X/9/5/956620ad60c6c2dd65758a387458f535f3b69fde.png)
Try using changesetArray
instead; the properties are case sensitive.
The query does not work it throws an error
![image](https://community.retool.com/uploads/default/original/3X/c/0/c0cd210182e3f1d1e42bf2905660aca128467d89.png)
In your table is the option to send the full row of data turned on?
![image](https://community.retool.com/uploads/default/original/3X/a/e/aee7df6109f82e35959954f8b1fed66b2a87b02f.png)
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