Hello,
I'm trying to merge records in my table when 3 criteria match.
I've been able to identify which records are duplicates, but I am having trouble merging them. Logically I believe my code should do what I want it do, I am not super familiar with asynch and I think that is what is messing me up.
When I run this code it throws:
Syntax error: await is only valid in async functions and the top level bodies of modules [script.js:33:9]
var table = base.getTable('Testing_500');
var query = await table.selectRecordsAsync();
//let records = query.records;
let upPN;
let upEM;
let upID;
//identify duplicates
let duplicates = query.records.filter((record) => {
return query.records.find((potentialDupe) => {
let fName = record.getCellValue("First Names") === potentialDupe.getCellValue("First Names");
let lName = record.getCellValue("Last Name") === potentialDupe.getCellValue("Last Name");
let resi = record.getCellValue("Residence") === potentialDupe.getCellValue("Residence");
let ident = record.id !== potentialDupe.id;
if (fName && lName && resi && ident){
if(record.getCellValue("Phone Number") == null && potentialDupe.getCellValue("Phone Number") !== null){
upPN = potentialDupe.getCellValue("Phone Number");
upID = potentialDupe.id;
}
if(record.getCellValue("Email Address") == null && potentialDupe.getCellValue("Email Address") !== null){
upEM = potentialDupe.getCellValue("Email Address");
upID = potentialDupe.id;
}
return record.id;
} //if
await table.updateRecordAsync(record, {
"Phone Number": upPN,
"Email Address" : upEM,
})
await table.deleteRecordAsync(potentialDupe.id);
})//return
});//let
console.log(duplicates)