Help

Re: Two updates in a row

409 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Emmanuel_Gilles
4 - Data Explorer
4 - Data Explorer

Hello guys,
I have a field that tracks the latest payment for a user based on a checkbox.
So basically every time i have a new payment, i’d like to ckeck the checkbox “payment” (if unchecked before). Otherwise, i’d like to uncheck then check it.
But the following code doesn’t do any update when the checkbox was already checked.
How can i make sure these two lines get executed ?

let record = queryResult.getRecord(recordId[0]);
//Uncheck the box if it was checked
if(record.getCellValue("Payment")){
                await table.updateRecordAsync(recordId[0], {
                "Payment": false
                });
    }
//Now recheck the box (or simply check it if it wasn't)
await table.updateRecordAsync(recordId[0], {
        "Payment": true
        });

Thanks for the help !

1 Reply 1

Try simplifying your code down:

let record = queryResult.getRecord(recordId[0]);
await table.updateRecordAsync(record, {
   "Payment": record.getCellValue("Payment") ? false : true
   });
}