I am trying to use a script in order to identify duplicate records in a table
Description:
- Duplicate record field = Participant Name
Desired outcome:
- When a duplicate record (repeated Participant Name) is created in the table labeled “Ops: Program Hub”
- Add a CHECK in the field “Duplicate”
THIS IS THE SCRIPT I HAVE - and it is currently not working. I am VERY new to scripts and would appreciate any help!
// the table to check
let table = base.getTable(“Ops: Program Hub”);
// the record we’re searching for duplicates of
// we need to create a ‘recordId’ input variable connected to a record trigger
let config = input.config();
let recordId = config.recordId
// the field to save duplicates in. this should be a self-linked record field
let duplicatesField = table.getField(“Duplicate”)
// query the table and find our record according to its id:
let query = await table.selectRecordsAsync({fields: });
let record = query.getRecord(recordId);
// search for duplicates
let foundDuplicates = query.records.filter((potentialDuplicate) => {
// if they’re the exact same record, they’re not duplicates:
if (potentialDuplicate === record) {
return false;
}
if (potentialDuplicate.name === record.name) {
// if the names match, we’ve found a duplicate:
return true;
}
return false;
});
console.log(Found ${foundDuplicates.length} duplicates of ${record.name}
);
// save the duplicates:
await table.updateRecordAsync(record, {
cduplicatesField.name]: foundDuplicates,
});