So I seem to be stuck. I have a table called People. 100s of records with them all associated with a Company Name (from Company Table). Some people are designated (checkbox) as being a billing contact or primary contact for a company. All of this is great. I made a view called People By Billing view that shows me just those marked
Now each year we sent out invoices. We have a table called Payments, with one record for each Company in the Company Table. This is all good. Here is where I am frozen. What I want to do is pull those that are marked as primary or billing from People to link in the Payments. We want this because we send out emails via the SendGrid tool to those people and attach the Payment ID to it so we can process.
I wrote a script that loops through a People By Billing and writes them to a linked record in Payments but it keeps overwriting the record already in the linked record, and honestly, I don’t feel like this needs to be a formula. I don’t want me client to have to run it. I want the People_Link to just pull those from the People By Billing View in People. The records you see in there now were pushed via my inefficient script! And Thanks as always! - Jon
I might as well add the script here in case someone can see where I am missing the addition to People_Link and not overriding.
let table = base.getTable("Payments");
let mainTable = table.getView("Current Year View Need to Pay");
let mainTableRecords =await mainTable.selectRecordsAsync();
//Substitute "Product" for table which contains range to search in
let table_look = base.getTable("People");
let lookupTable = table_look.getView("People By Billing View");
let lookupRangeRecords =await lookupTable.selectRecordsAsync();
//Replace "Item.barcode" with column name which has the values you want to look up
for(let record of mainTableRecords.records){
let lookupValue = record.getCellValue("Company Name")[0]["name"];
let existingLinks = record.getCellValue("People_Link");// Get existing links from the 'Projects' field
console.log(lookupValue+"Is the lookup company");
console.log(record.getCellValue('People_Link'));
for(let rangeRecord of lookupRangeRecords.records){
TBH, i don’t like using ‘for’, so I changed it in other way. I couldn’t test it as it needs much time to create test table
let table = base.getTable("Payments"); let mainTable = table.getView("Current Year View Need to Pay"); let mainQuery = await mainTable.selectRecordsAsync();
//Substitute "Product" for table which contains range to search in let table_look = base.getTable("People"); let lookupTable = table_look.getView("People By Billing View"); let lookupRange = await lookupTable.selectRecordsAsync();
Added .slice(0,5) to update first 5 records, not the whole table. and confirmation with ‘Continue’ So you can check and evaluate before doing full update. To update whole table - just remove slice part.
TBH, i don’t like using ‘for’, so I changed it in other way. I couldn’t test it as it needs much time to create test table
let table = base.getTable("Payments"); let mainTable = table.getView("Current Year View Need to Pay"); let mainQuery = await mainTable.selectRecordsAsync();
//Substitute "Product" for table which contains range to search in let table_look = base.getTable("People"); let lookupTable = table_look.getView("People By Billing View"); let lookupRange = await lookupTable.selectRecordsAsync();
Added .slice(0,5) to update first 5 records, not the whole table. and confirmation with ‘Continue’ So you can check and evaluate before doing full update. To update whole table - just remove slice part.
Hm I feel like I’m missing something, sorry. People are linked to Companies, and Companies is linked to Payments, right?
If so, what if we tried the following?
Create a conditional lookup field in Companies that displays the record IDs of people who have either the Billing Contact or Primary Contact checkbox ticked
Create a lookup field in Payments to display the record IDs of those People
Create a formula that will check whether the value of the lookup field is the same as the value in People_Link
Create an automation that will trigger off of the formula field, and if it’s not a match, it’ll paste the value from the lookup field into the linked field to update the link
TBH, i don’t like using ‘for’, so I changed it in other way. I couldn’t test it as it needs much time to create test table
let table = base.getTable("Payments"); let mainTable = table.getView("Current Year View Need to Pay"); let mainQuery = await mainTable.selectRecordsAsync();
//Substitute "Product" for table which contains range to search in let table_look = base.getTable("People"); let lookupTable = table_look.getView("People By Billing View"); let lookupRange = await lookupTable.selectRecordsAsync();
Added .slice(0,5) to update first 5 records, not the whole table. and confirmation with ‘Continue’ So you can check and evaluate before doing full update. To update whole table - just remove slice part.