Sep 13, 2022 04:34 AM
I am using this app that @Alex.Wolfe published (THANK YOU ALEX)! , and am hoping to make some tweaks so that I can use linked records fields.
Right now the app allows you to create one record in another table for each option in a multiple select field in the source table, and links the new records back to the source record.
Which is exactly what I need, but I believe it’s set up so the options from the multiple select cannot be outputted into a linked records field in the second table.
Here’s my used case scenario:
What I want to change:
Is this possible? Thank you for your help!
Sep 13, 2022 09:37 AM
Hi Lisa :wave:
First, glad to hear the script is helpful!
Second, there definitely is a way to use linked records instead. It just requires some slightly different code. This example base in our Universe has one way of doing it built in using a Scripting extension.
To answer your question around Automations (from DM)
I’ve added a version of my script (see below) for this you can use to adapt to your base. Note you’ll need to add some inputs from the Automation Trigger, to tell it which record to use (the record you want to create deliverables for).
Here’s how to setup the Automation
In your Automation, you’ll want to add input variables (left-hand side of the Automation Run a Script Action window) for the following:
deliverablesToCreate
=> this should be the multiple select field values inserted from your trigger steprecordID
=> this should be the Airtable record ID value inserted from your trigger stepHere’s the Automation-friendly version of the code where you’d want to update the variables before the “DO NOT EDIT” section:
let { deliverablesToCreate, recordID } = input.config(); // Values passed from the trigger record
console.log(deliverablesToCreate); // Log to console
let delivField = 'Deliverables'; // Field name or ID of multiple select field
let tableDest = base.getTable('tblXXXXXXX'); // Destination table name or ID
let destinationField = 'Name'; // Primary field name or ID you wish to populate the Deliverables name into
let projField = 'Projects'; // Linked record field name or ID back to source table records
//
//
// ———— * DO NOT EDIT * ————
if (deliverablesToCreate.length > 0) {
// Create records
let dToCreate = [];
for (let i = 0; i < deliverablesToCreate.length; i++) {
let name = deliverablesToCreate[i]
dToCreate.push({
fields: {
[destinationField]: name,
[projField]: [{ id: recordID }]
}
})
};
// Batches the creation
while (dToCreate.length > 0) {
await tableDest.createRecordsAsync(dToCreate.slice(0, 50));
dToCreate = dToCreate.slice(50);
}
// Output confirmation for the user
console.log(`${deliverablesToCreate.length} records created ✅`);
} else {
console.log(`No deliverables chosen for this record. Make selections in the ${delivField} field first.`)
};
Sep 14, 2022 04:43 AM
@Alex.Wolfe , AMAZING, thank you SO much for this!
I did get one error:
Error: Field “fldjuDEGf1Rlj0WKg” cannot accept the provided value.
at main on line 61
Any idea for what I might have done wrong?
Sep 14, 2022 05:04 AM
Update: @Alex.Wolfe , I think I figured it out! I had selected the linked record field rather than the multi-select field so I think that’s what caused the error! Switching it to the mult-select field made it work perfectly. THANK YOU!
Sep 14, 2022 09:24 AM
Awesome glad to hear you got this working! :raised_hands: