Apr 01, 2022 04:06 AM
I have a table with created date column and some data, as soon as new record is created I have created a automation script the extracts the newly created record by sorting this column in descending order and getting the getting the first record by using query.records(which is the last record created, because it is in descending order).
My question is, is there any way other than this to extract the latest record created?
I also have a column that is auto increment id, I was thinking of extracting the highest value from this column as the latest record, but could not find how to find max value of column by writing in automation script.
Apr 01, 2022 11:47 AM
Does your automation script need to find the latest record or do you need to indicate the latest record for something outside of the automation?
If your automation script wants the latest record, and your automation us running off a “record is created” trigger, that triggering record is the latest record at the moment it was created. Thus the automation script can simply use the triggering record as the latest record.
If you need to have a different way of indicating the latest record, such as a checkbox field marked for the latest record. Have an automation run whenever a new record is created that clears the checkbox from the one previous record with the checkbox, and then sets the checkbox in the new record.
Apr 02, 2022 06:19 AM
Hey, thank you for replying
Yes, I am writing 2 automation scripts for both - when the record is created for one table and when checkbox is ticked for another table, my question is how do you use the triggering record in script or how do you get the id of triggering record in script?
I don’t want to sort all the records and get the latest record, I was wondering if there is any other way.
Apr 02, 2022 07:20 AM
Use an input variable. Create the variable in the left pane of the script editor and set the value to the record ID.
Then in the script, use
input.config to get the value of the input variable.
const inputConfig = input.config() const recordID = inputConfig["recordId"]
Apr 02, 2022 07:30 AM
Looks like this is a duplicate thread that has already been answered: