Hello, sometimes airtable automations return bad input variables after changing record input value.
I changed DESIGN_STATUS to Needs fixing, and Customer_status field changed to Waiting via automation. But my code says that when status become Needs fixing, it need to do other thing.
Its happens very rarely.
This is my code problem or air table ? What I need to do ?
My code:
let data = input.config();
let table = await base.getTable('Orders V3');
let view = await table.getView("FULL ORDER LIST AUTOMATIONS");
if(data.Design_status == "Needs fixing"){
await table.updateRecordAsync(data.RecordId, {"Customer_status": {"name": "Needs revisions"}});
} else if(data.Design_status == "Supervisor approved"){
//Time to send reminder
const sending_time = new Date( Date.now() + 2 * 24 * 60 * 60 * 1000 )
var dd = String(sending_time.getDate()).padStart(2, '0');
var mm = String(sending_time.getMonth() + 1).padStart(2, '0');
var yyyy = sending_time.getFullYear();
var today = mm + '/' + dd + '/' + yyyy;
let query = await view.selectRecordsAsync();
var records_to_update = [];
for (let record of query.records) {
if(record.getCellValueAsString("Name") == data.ID){
records_to_update.push(record.id);
if(record.getCellValueAsString("Design_status") != "Supervisor approved") {
records_to_update= [];
break;
}
}
}
if(records_to_update.length > 0) {
for (let record_id of records_to_update) {
await table.updateRecordAsync(record_id,{
'Cron_time': today,
'Sended': true,
})
}
}
await table.updateRecordAsync(data.RecordId, {"Customer_status": {"name": "Waiting"}});
}