Help

Re: Script to Link Same Table But Only Find Duplicates?

1660 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Grow_With_Jen
7 - App Architect
7 - App Architect

Ok, I have this script, but I need to check only for duplicates in the same table. Thoughts on what I need to add to ensure the record pulled is not self linking in linked records?

//Define the table and query

let jobTbl = base.getTable(“Caregiver Applicants”);

let appQuery = await jobTbl.selectRecordsAsync();

//Loop through the records and find the Applicant

for (let record of appQuery.records) {

 let appname = record.getCellValue("E-mail");



//Define linked table and query

let applicantTbl = base.getTable("Caregiver Applicants");

let applicantQuery = await applicantTbl.selectRecordsAsync();



//Loop through linked table and match ID values

for (let appRecord of applicantQuery.records) {

    if (appRecord.getCellValue("E-mail") === appname) {

        let inputid = appRecord.id;

     

        //Update field

        jobTbl.updateRecordAsync(record, {

            "Additional Records": [{id: inputid}]

        });

   }

}

}

This ends up linking the original record to itself. Ugh.

14 Replies 14

Hi Jonathan! How are you?
I’m trying to use this code to mark duplicates in my table, but I don’t get any phrase in the “duplicate” field.
I just change the name of the table, is called “juli”.
The script runs succesfully, but even then, I don’t get “this is a duplicate” or anything really.
Is it OK that I’m writing this code inside an automation?
I’ve already try with two triggers:

  • If I enter a new record
  • Every 15 minutes
    But either way, I don’t get any result.
    Thank you in advance!

Here is the code:

let applicantsTbl = base.getTable(‘juli’);

let applicantsQuery = await applicantsTbl.selectRecordsAsync();

// make an array of all of the emails

let emails = applicantsQuery.records.map(record => {

return record.name

})

// filter to get emails which are duplicates of another

let dupes = emails.filter((item, index) => emails.indexOf(item) != index);

// refine this with Set to the unique set of duplicates

let uniqueDupes = […new Set(dupes)];

// iterate through the records and update this with a duplicate

for (let record of applicantsQuery.records) {

for (let dupe of uniqueDupes) {

    if (record.getCellValue('Email') == dupe) {

        await applicantsTbl.updateRecordAsync(record, {

            'Duplicate': 'This has a duplicate'

        })

    }

}

}

image

@Noamsay can you maybe help me with this script? Thanks!

Hi @Maira_Masson - I think this is the same problem noted further up the chain. The primary field in your table is Name and Email is one of the other fields. If we want to match on Email (which is what the script does towards the end), you need to change this part of the script:

let emails = applicantsQuery.records.map(record => {
  return record.name
})

to this:

let emails = applicantsQuery.records.map(record => {
  return record.getCellValue('Email')
})

Thank you!! It’s working now.
I need to adapt this script to be use in an URL field. We need to mark the duplicates comparing between LinkedIn profiles URLs, instead of Emails. How should I adapt this?

Thank you in advance!

@Maira_Masson - you need to reference the url field instead of the email field, so two changes I think:

This:

// make an array of all of the emails
let emails = applicantsQuery.records.map(record => {
    return record.name
})

becomes:

// make an array of all of the emails
let emails = applicantsQuery.records.map(record => {
    return record..getCellValue('URL')
})

and this:

for (let record of applicantsQuery.records) {
    for (let dupe of uniqueDupes) {
        if (record.getCellValue('Email') == dupe) {
            await applicantsTbl.updateRecordAsync(record, {
                'Duplicate': 'This has a duplicate'
            })
        }
    }
}

becomes:

for (let record of applicantsQuery.records) {
    for (let dupe of uniqueDupes) {
        if (record.getCellValue('URL') == dupe) {
            await applicantsTbl.updateRecordAsync(record, {
                'Duplicate': 'This has a duplicate'
            })
        }
    }
}

I haven’t tested this out, but it should work OK.