Nov 19, 2020 01:37 PM
I’m looking to use the suggested Mark Duplicate script within the scripting app. I copy and pasted the script, ensured I had the linked “Duplicate of” field made (or at least I think I made it properly :rofl: ) and yet I get the error:
TypeError: Invalid arguments passed to recordQueryResult.getRecord(recordId):
• recordId should be a string, not undefined
at main on line 14
// the table to check
let table = base.getTable(“Feature requests”);
// 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 of”);
// query the table and find our record according to its id:
let query = await table.selectRecordsAsync();
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, {
[duplicatesField.name]: foundDuplicates,
});
Not being a person who does script myself, I’m unclear on how to resolve. Any help would be greatly appreciative.
I’m looking to use the script to identify those which have already applied to our program, and therefore are already in our database so that we can review the past application along with the new one and forego having to search for a duplicate of each new applicant manually.
Nov 19, 2020 02:25 PM
The script you’re using is designed for an Automation “Run script” action, not the Scripting App. The reason you got the “undefined” error is because the script is looking for a Record ID value to be passed into it via input.config()
, which is an Automations-exclusive feature (the idea being that the script would pull the record ID from whatever record triggered the automation).
If you want to use the Scripting App, you’ll have to replace:
let config = input.config();
let recordId = config.recordId;
with:
let record = await input.recordAsync("Pick a record", table)
let recordId = record.id
Nov 20, 2020 07:55 AM
@Kamille_Parks it is being done in the automation, and not within the scripting app itself. It’s just that the scripting app had the script :slightly_smiling_face:
Here are images of the automation with script and the error provided
When I updated to your replacement of
let record = await input.recordAsync(“Pick a record”, table)
let recordId = record.id
I was given a syntax error message.
I’m wanting it to compare the email address column that I have, and I did select that for the input.config ( see image below ) do I need to make the email address my records primary field instead of an additional field to the table?
see image
Nov 20, 2020 09:02 AM
Pardon the confusion. This post was tagged as “Scripting App”, not “Automation”, and the original post says “within the scripting app,” which is why my first reply edited the script to work in a Scripting App (replacing input.config
with await input.record...
). I’ve recategorized this post accordingly.
Since you are in fact doing this in an Automation, leave your script how it was originally and add your missing input variable for the trigger record’s record id. Based on the original script, the name for that input variable should be recordId
.