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

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!

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

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.