Hello! I am a first-time poster using the following template script which is part of the Airtable +Add an app section (script below).
I am using Airtable for hiring. Within my Applicants table, I have people (field name: Applicant Name) who have applied for multiple positions (field name: Active Positions Applied For) of which some are under consideration (field name: Active Positions Under Consideration). I am looking to automate rejection and advancing to next stage emails but am running into difficulty with the following scenarios due to multiple selection:
- Candidate applies for 2+ positions, of which 0 are under consideration – want to send separate rejection emails to positions applied for (current automation sending as one combined email only)
- Candidate applies for 2+ positions, of which 1 is under consideration – want to send rejection email to position not under consideration only
- Candidate applies for 2+ positions, of which 1 is under consideration and then later no longer under consideration – want to send separate rejection email to both without duplication / re-sending original
Would creating a child table (table name: Test) off the parent (table name: Applicants) data using the script template resolve this issue as I can build automations based off single rows in the child table? Eg. Person applies to 3 positions and each position is handled separately with separate reject / advance email
Getting an error on Line 36 when I run script below: TypeError: Cannot read property ‘length’ of undefined at main on line 36
Not sure that I have chosen my 5 options correctly. Essentially, I want all data in Applicants table to be shown in the Test table but with each position applied for and subsequent position/s under consideration being its own row eg. applied for and under consideration Position A = 1 row
Is there an alternative way to turn a multiple select into separate rows all linked to the same person?
Is there an IF statement or formula for only sending separate rejection emails to Active Positions Applied For that DO NOT MATCH Active Positions Under Consideration?
Any recommended resources to address my goals are appreciated!
Thank you for your help! Script below.
// Script settings
let s = input.config({
title: ‘ Create records from multiple select field options’,
description: ‘Creates 1 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.’,
items: r
// Source table select
input.config.table(‘tableSource’, {
label: ‘ Table with existing records’
}),
// Source table: Multiple select field with deliverables
input.config.field(‘delivField’, {
parentTable: ‘tableSource’,
label: ‘ Multiple select field with names of records to create’,
}),
// Destination table select
input.config.table(‘tableDest’, {
label: ‘ Table to create new records in’
}),
// Destination table: Name or title field
input.config.field(‘destinationField’, {
parentTable: ‘tableDest’,
label: ‘ Deliverable name or title field in destination table’,
}),
// Destination table: Linked record field (back to the Source table record)
input.config.field(‘projField’, {
parentTable: ‘tableDest’,
label: ‘ Linked record field (links to table with existing records)’,
}),
]
});
// You can use a button field that points to this script to run it for specific records,
// or you can run the script directly, in which case the following prompts the user to pick a record
let r = await input.recordAsync(‘Pick a record’, s.tableSource);
// Gets the desired # of records to create, and deliverable names, based on the fields chosen in the script settings
let recToCreate = s.delivField.options.choices.length;
let deliverables = r.getCellValue(s.delivField.name);
// Variables to store the applicable deliverable names and length (total records to create)
let delivNames = ;
let length = 0;
if (deliverables) {
// Creates record names from ‘deliverables’ multiple select field, if any
for (let item of deliverables) {
delivNames.push({
‘Name’: item.name
})
}
length = delivNames.length
// Preview records to create, prompt user to confirm creation
output.markdown(’### Create ’ + length + ’ records for ’ + r.name + '?’);
output.table(delivNames);
await input.buttonsAsync(’’, <{ label: ‘Create records’, value: ‘Create records’, variant: ‘primary’ }]);
// Create records
let dToCreate = ;
for (let i = 0; i < length; i++) {
let name = delivNamesfi].Name
dToCreate.push({
fields: {
s.destinationField.id]: name,
rs.projField.id]: <{ id: r.id }]
}
})
};
// Batches the creation
while (dToCreate.length > 0) {
await s.tableDest.createRecordsAsync(dToCreate.slice(0, 50));
dToCreate = dToCreate.slice(50);
}
// Output confirmation for the user
output.markdown( ${length} records created
);
} else {
output.markdown(**No deliverables chosen for this record. Make selections in the ${s.delivField.name} field first.**
)
};