BulkUpdate assistance

Hi Retool,

Hoping you could help me. I currently have a query that displays into a table. The table has a few editable fields.

I use the Bulk Update feature and so far, it's working great.

TABLE: dbo.PROPERTY
Action Type: Bulk update via a primary key
Primary Key Column: PROPERTY_ID
Array of records to update: {{table2.recordUpdates.map(row => _.omit(row, ["description"]) ) }}

This works because the queried/displayed field names matches the database table field names. I omit description as that is derived from somewhere else.

In my table, I have two other fields:
LAST_UPDATE_DATE
LAST_UPDATED_BY

I would like to update these fields with the system date and current_user.id.

Questions:

  1. Is there an easy way to do this within this BulkUpdate query?
  2. Does BulkUpdate update all the rows in the table or just the specific row(s) that have changed? (If it changes all rows regardless of change or not, this might defeat the purpose).

Much appreciated!

@PL13,

  1. Hmmm, not done this, but I might set you on the right path (in other words make you do the work so I know the answer for when I need it :wink:) Try something along the lines of:

    {{table2.recordUpdates.map(row => _.omit(row, ["description"].set(row, {'LAST_UPDATE_DATE'}, moment()).set(row, {'LAST_UPDATED_BY'}, 'Fred') }}

Lodash docs are here: Lodash Documentation

  1. recordUpdates is only the updated records so only those are sent.

Thanks @bradlymathews. I like the direction you're going with this.

I focused on LAST_UPDATE_DATE. I tweaked the syntax slightly and tried:

{{table2.recordUpdates.map(row => _.omit(row, ["description"]).set(row, ["LAST_UPDATE_DATE"], moment()) ) }}

I received:

!Data must be an array
statusCode:422
error:"Unprocessable Entity"
message:"Data must be an array."
data:null

I've dumbed it down to see if I could get LAST_UPDATE_DATE to populate, trying both:

{{table2.recordUpdates.map(row => _.set(row, ["LAST_UPDATE_DATE"], moment()) ) }}
and
{{table2.recordUpdates.map(row => _.set(row, {'LAST_UPDATE_DATE'}, moment()) ) }}

I still receive the same error "Data must be an array."

I feel like I'm missing something very minor here. Any suggestions?

Much appreciated!

Put this into a transformer so you can Preview what it is that is actually being sent to your server. Could be .set() is the wrong way to go or the syntax still isn't quite right. This will get you more visibility into it anyway.

Transformers work a little different so you will need to extract recordUpdates so your trasnformer will look something like this:

let records =  {{table2.recordUpdates}}
return records.map(row => _.omit(row, ["description"]).set(row, ["LAST_UPDATE_DATE"], moment()) )
1 Like

Hi,

I do the same pass through into two column, last user and modified date. I'm using a JS transformer to determine the values and pass it into the two columns:

Afterwards in your bulkupdate query the array to be passed needs to reference the transformer.value.

Array of records to update
{{enhancedRecordUpdates.value}}

1 Like

@bradlymathews and @Nicolas

Thank you so much!

The transformer did the trick followed by the BulkUpdate referencing the new array. Simply Amazing!

This is a very helpful post and hopefully others can make use of it.