Hi all!
Pretty new to this, but I'm trying to write a script similar to Airtable's child-record script. The script should: For parentTable (defined in config), when a record's value in a field (singleSelect defined in config) matches conditions (defined in config), then it should assign this record as parentRecord, and create a link child-record in a childTable (defined in config) and populate this record's primary field with the value from the parentRecord's primary field.
I am having some issues with the config, and wondered if anyone knew how to fetch the options of a field specified in input.config.field so it appears as the options in a input.config.select dropdown list. I want to avoid hard-coding it, but it is an easy workaround if it's impossible.
Here's the code I have for the config.
const config = input.config({
title: `Conditional Parent-child record creation`,
description: `For records in a parent table with a matching value of a designated field, this script will create a
number of "child" records in another table, where each "child" references the "parent" through a Linked Record field.`,
items: [
input.config.table('parentTable', {
label: 'Parent Table',
description: 'Select the parent table',
}),
input.config.field('fieldToCheck', {
label: 'Field to check',
description: 'Select the field containing the value to check',
parentTable: 'parentTable',
}),
input.config.select('valueToMatch', {
label: 'Value to Match',
description: 'Select the value to match records in "Field to check" against',
options: [
//this section is unknown
],
})
]
});
My first idea was to define a variable fieldToMatchValue before the config variable is defined, and reference back to this value when writing the options (under input.config.select('valueToMatch', { etc…)
Anyone know of a way to do this?
The purpose of this is primarily multi-language workflows, where the parentRecord is an English string, and theres a child-record for each English string for many languages in a different table. The fieldToCheck is a single-select field indicating the status of the record in a workflow, "translation" being the final stage before "done". The translators would automatically be assigned a record based on the language-tag associated with it, through an automation that checks a table of language-assignments against a user upon the record being created, and assigns the relevant employee.
Appreciate all help!