Help

Filter Records Where Link to Another Record Field Doesn't Contain Particular Record

762 1
cancel
Showing results for 
Search instead for 
Did you mean: 
StevenB
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello,

I have two tables (“Table 1” and “Table 2”) that are linked on a single field (“My Field 2”) with a many-to-many relationship.

I’m trying to write a script to gets all of the records from the table Table 1 where the field My Field 2 does not contain a particular linked record from table Table 2. I know how to write this script normally, but because field My Field 2 on both tables Table 1 and Table 2 allow linking to multiple records I know that I need to use an array in the filter in my script and can’t seem to get that part correct.

Code is below. If someone could help me get the array correct in the filter, I would really appreciate it!

let tableMyTable1 = base.getTable("MyTable1")
let queryMyTable1 = await tableMyTable1.selectRecordsAsync();
let recordsMyTable1 = queryMyTable1.records.filter(records => { !(records.getCellValue("MyField2").includes(recordMyTable2)) })

Thank you so much!

1 Reply 1

Try the following:

let recordsMyTable1 = queryMyTable1.records.filter(records => { 
   !(records.getCellValue("MyField2").map(x => x.id).includes(recordMyTable2.id)) 
})

^ This way you’re comparing a single string value against a list of strings as opposed to an object against a list of objects