Hi all--
We have a form that staff use to pitch a new idea or project for our organization. We want to connect their name and email (as submitted in the form) to a preexisting linked record with their details. Sometimes, staff will fill in multiple names and emails at once, separated by commas. This would look something like this:
[PROJECT LIST TABLE]
[Project Name Field]: Special Event
[Name Field] : John Doe, Jane Doe
[Email Field]: johndoe@org.com, janedoe@org.com
[Project Details Field]: A special event that we will be working together to create for the organization.
I would like to have an automation or script pull apart the comma-separated values, search for each one in the linked Staff table, and if the name or email exists in the linked table, add that name/email's linked record to a separate [Project Staff] field in the Project List table. Theoretically, it's simple! But it's been about a decade since I've done any scripting, and if lack of practice makes one "rusty," I'm probably closer to "disintegrating." Below was my stab at coding a script, but I'm getting an error about the array not being iterable, and I'm certain it's got other issues as well.
//get Input from new record
let inputconfig = input.config();
//get Name & Email Submitted field data
let nameString = inputconfig.Name;
let emailString = inputconfig.Email;
//split name data by the word "and", "(", or ","
nameString = nameString.replace(')','');
let nameArray = nameString.split(' and ').join(',').split('(').join(',').split(',');
//split email data by the word "and", ";", or "," and clean up emails
let emailArray = emailString.split(' and ').join(',').trim().split(',');
//contact the Staff table and get access to full name & email address fields
let staffTable = base.getTable("Staff");
let queryArray = await staffTable.selectRecordsAsync({
fields: ["Email Address", "Full Name"]
});
//create I iterative variable
let i=0;
//connect Staff Name from Staff Table to Pitching Staff field
for (const name in nameArray){
for (const record of queryArray[i]){
if (record.getCellValueAsString("Full Name").toLowerCase() == nameArray.toString().toLowerCase()){
output.set("Pitching Staff", record.id )
i++
}
else if (record.getCellValueAsString("Email Address").toLowerCase() == emailArray.toString().toLowerCase()){
output.set("Pitching Staff", record.id )
i++
}
};
};
Nobody else on my team has experience coding or scripting; it was not part of the job requirements. As such, I'm happy to try and learn how to fix my code OR just have a solution given. However, I'm looking for a solution that does not require an external/non-Airtable extension.
Thank you for your time.