Hi there :slightly_smiling_face:
I’m trying to batch update a date field in a specific view. The new dates are coming from a formula field (I’ve assumed the output of the formula field in the scripting app is a date because it’s formatted as such in the table). It runs with no errors but the dates aren’t actually being updated in the table and I’m not sure why. If anyone can pick up from my code why it isn’t updating, I would really appreciate it.

Update loop not actually updating
Best answer by kuovonne
This is a dangerous assumption. It probably is a date, but it might be a text string that looks like a date. Can you post the formula?
How sure are you of the value of the variable sure? Can you do a console.log("sure is " + sure) right after it is set? Can you put another console.log inside the if block to be sure that it is running?
These lines are probably part of the reason you don’t see any errors. Try replacing them with this.
await dev.updateRecordAsync(query.records[i], {
[field_ed.name]: next_date,
[field_rent.name]: next_rent,
});
I removed the .name from the record because the first parameter to updateRecordAsync needs to be a record or a record id, not a record name. I added the keyword await so that the script will wait for the update to complete before continuing. The error was probably due to passing in the record name, and not having await hid the error because the script ended before it had a chance to show you the error.
I also combined updating both fields in one call. Eventually you will want to batch process the updates in batches of 50 outside the loop, but that is a different skill for a different day.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
