May 04, 2021 05:14 PM
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:
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: ‘ :part_alternation_mark: 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: [
// Source table select
input.config.table(‘tableSource’, {
label: ‘ :fallen_leaf: Table with existing records’
}),
// Source table: Multiple select field with deliverables
input.config.field(‘delivField’, {
parentTable: ‘tableSource’,
label: ‘ :fallen_leaf: Multiple select field with names of records to create’,
}),
// Destination table select
input.config.table(‘tableDest’, {
label: ‘ :seedling: Table to create new records in’
}),
// Destination table: Name or title field
input.config.field(‘destinationField’, {
parentTable: ‘tableDest’,
label: ‘ :seedling: 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: ‘ :seedling: 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 = delivNames[i].Name
dToCreate.push({
fields: {
[s.destinationField.id]: name,
[s.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.**
)
};
Mar 11, 2022 07:08 AM
I have not found a way to copy from the Multi select field dropdown. That was the first solution that I tried.
Mar 14, 2022 06:01 AM
Maybe I’m still misunderstand. Ok, I will try to explain with demo. Imagine you have table Users with some events (muliselect field LinkEv)
Create new table Events (remove default 3 records & 3 fields),
In table Users, create link field to it and copy-paste
result will be every single multiselect option in primary field of Events table.
===========
Note: if you need just a list of options, you don’t need second table and you can do the task in 15 seconds
Just duplicate, then turn to text, then again to multiselect, but don’t press Save, copy-paste
I hope it will help you.
Mar 14, 2022 07:35 AM
Thanks Alexey_Gusev ! I will try this solution.
Mar 14, 2022 08:28 AM
When I just started, I had some troubles without understanding of basic thing - how copy-paste works for linked field.
When you copy-paste something into linked field, Airtable iterates all possible values to link (ignoring “Limit record selection to a view”). and choose first to match
If it found nothing, it will create new record and link to it.
comma separated text considered as several values. symbol ‘&’ also means something, it should be taken into account when working with such data
Mar 16, 2022 10:26 AM
I appreciate your help so far. :pray:
I am trying to make a list of all the options from the Findings column. (see attached)
I tried your suggested method:
duplicating the column
See your version vs. what it showed me. Can you help me troubleshoot?
Mar 16, 2022 03:06 PM
Hi! Running into an issue with this script and not sure what i’m doing wrong…
Mar 18, 2022 01:01 PM
But when I changed the field type to Text it did not list them out
Correct, it will just change it to text, when you press Save.
Then try to change this text field and choose multiselect and you will get the list.
It’s the “side feature” of converting text to select.
Note that you can also check duplicates in such way, because values in this list sorted by frequency in decreasing order.