Mar 25, 2020 02:06 PM
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.
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.
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.
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 🚀')
Jan 04, 2022 04:38 PM
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.
Feb 25, 2022 12:18 PM
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!