Skip to main content

Script to flag duplicate records


Lucas_Ravassall
Forum|alt.badge.img+6

Hi, I need a script to detect duplicates in a list with many records (15k+), I need the records column to work as a flag and that by means of a text or a checkbox notify me if I am adding any mail that is already above. The idea would be a real time process as fast and efficient as possible, that when someone finishes copying the new mail it will notify me if it is already up there

Thanks!

5 replies

Forum|alt.badge.img+16
  • Inspiring
  • 532 replies
  • June 10, 2022

Hi @Lucas_Ravassallo
There is a free dedupe application in the marketplace that you can run to find and merge duplicates.


Alexey_Gusev
Forum|alt.badge.img+23

Hi,
You don’t need a script for it, if you want it to be done in real time.
You should add an automation that runs for each “Record created”.
Action will be “Find records” in your table, condition - email=email from new added record.
Then it should contain conditional action based on the length of ‘Find Records’ answer, like this

Action should update some field by your choice. To update checkbox field, you can put 1 or 0 into it. Also it can be true/false(or space, I don’t remember 100%)


Alexey_Gusev
Forum|alt.badge.img+23

For checking duplicates via script run, you can use this script, adjusting first 2 lines


const table=base.getTable('Your Table')
const [CHECK,MARK,HASDUP,DUP,UNIQ]=['field to check','field to mark','Has duplicates','Duplicate','Unique']
const query=await table.selectRecordsAsync({fields:[CHECK]})
const values=new Map(query.records.map(rec=>[rec.getCellValue(CHECK),rec.id]))
const others=query.recordIds.filter(id=>(![...values.values()].includes(id)))
const othervals=new Set(others.map(id=>query.getRecord(id).getCellValue(CHECK)))
const uniq=[...values.keys()].filter(val=>!othervals.has(val))
const upd=query.records.map(rec=>({'id':rec.id,'fields':{[MARK]:uniq.includes(rec.getCellValue(CHECK))?
UNIQ: others.includes(rec.id)? DUP:HASDUP}}))
while (upd.length) await table.updateRecordsAsync(upd.splice(0,50))

  • New Participant
  • 2 replies
  • September 19, 2022

If you’re still looking for solutions for flagging duplicate records I recommend checking out what we made at zzBots. Here is a link to our community forum that includes written and video instructions of how to install our " Airtable Flag Duplicate Records" plugin (pre-built bot).

I hope you find this helpful:)


Forum|alt.badge.img+4
  • Participating Frequently
  • 9 replies
  • December 30, 2023
Alexey_Gusev wrote:

For checking duplicates via script run, you can use this script, adjusting first 2 lines


const table=base.getTable('Your Table')
const [CHECK,MARK,HASDUP,DUP,UNIQ]=['field to check','field to mark','Has duplicates','Duplicate','Unique']
const query=await table.selectRecordsAsync({fields:[CHECK]})
const values=new Map(query.records.map(rec=>[rec.getCellValue(CHECK),rec.id]))
const others=query.recordIds.filter(id=>(![...values.values()].includes(id)))
const othervals=new Set(others.map(id=>query.getRecord(id).getCellValue(CHECK)))
const uniq=[...values.keys()].filter(val=>!othervals.has(val))
const upd=query.records.map(rec=>({'id':rec.id,'fields':{[MARK]:uniq.includes(rec.getCellValue(CHECK))?
UNIQ: others.includes(rec.id)? DUP:HASDUP}}))
while (upd.length) await table.updateRecordsAsync(upd.splice(0,50))

I tried your script
by changing the second line like this
const [CHECK,MARK,HASDUP,DUP,UNIQ]=['PHONE','duplicates','A duplicates','Duplicate','Unique']

I just want a script that iterates through the phone column customer table and checks for duplicate phones
THANK YOU

I receive this message

ERROR Error
: the field "fldHrLg5ZiN1ETeaY" cannot accept the value provided.
to main line 10

 


Reply