Help

Bulk Add a Linked Records to Fields that have existing linked records

Topic Labels: Scripting extentions
9159 11
cancel
Showing results for 
Search instead for 
Did you mean: 
VictoriaPlummer
7 - App Architect
7 - App Architect

Hey Y’all,

So sometimes I find myself in a situation where I want to do something that sounds simple: I want to link a record to multiple records at a time. Which is usually easy if there’s only one linked record present in a field, but not so much if linked records already exist. For example: Say I want to add Christmas Day to everyone’s PTO requests in the below table.

Screen Shot 2020-03-25 at 4.47.42 PM

I can’t copy and paste because that will overwrite the existing records and I want to keep those. I can technically update it bulk from the PTO Requests table, but only if I have my People names in a comma separated array, which I don’t. So I’m using a script.

Screen Recording 2020-03-25 at 04.52 PM

I’m sure you can dial this in to your needs a little bit more, but this script works by adding everyone in the People table to the visible records in the Holiday view of the PTO table. Example base here. Script here

let ptoTable = base.getTable('PTO');

let holidayView = base.getTable('PTO').getView('Holidays');

let holidayQuery = await holidayView.selectRecordsAsync();

let holidayRecords = holidayQuery.records;

let peopleTable = base.getTable('People');

let peopleQuery = await peopleTable.selectRecordsAsync();

let peopleRecords = peopleQuery.records;

let d = []

peopleRecords.forEach(c => d.push({id: c.id}));

let updateRecords = holidayRecords.map(c=> ({id:c.id,fields:{'Person': d}}));

await ptoTable.updateRecordsAsync(updateRecords);

output.markdown('# Done 🚀')

If you want to go ahead and choose which record you’re bulk adding, you can use the input method.
Screen Recording 2020-03-25 at 05.04 PM

let ptoTable = base.getTable('PTO');
let holidayRecord = await input.recordAsync("Enter the Holiday you'd like to add to everyone's PTO",ptoTable)
let peopleTable = base.getTable('People');
let peopleQuery = await peopleTable.selectRecordsAsync();
let peopleRecords = peopleQuery.records;

let d = []
peopleRecords.forEach(c => d.push({id: c.id}));
await ptoTable.updateRecordAsync(holidayRecord.id,{
    
    'Person': d

}
    
);
output.markdown('# Done 🚀')
11 Replies 11

Hi Rosie - Welcome!

From the explanation of your example, I would say yes. I’d use .getView() to curate the list of parts you’d like to bulk add to a product.

Tom_Krumins
4 - Data Explorer
4 - Data Explorer

Hi @VictoriaPlummer , this script looks fantastic, and I would like to adjust it to fit my organization’s workflow.

Tables
Targets table (organizations or individuals we want to pursue)
Interactions/Outreach table (ways we engage with targets, such as bulk emails)

Goal: add a bulk email to different target groups, each with its own View filtered by a Multiple Select Field tag.

Step 1 - select the Interaction/Outreach record (e.g. “bulk email - Jan 18”
Step 2 - select the View to add the linked record
Step 3 - celebrate!

We’re a nonprofit working to deliver several million dollars in direct cash relief, so this would save us an enormous amount of time. Thank you!