Create script to create records of a combining data from 2 lists from "find records" in previous automation steps
Hello,
I am having trouble getting a script to automatically generate records from two lists: bonus plan and staff list into “bonustable”. I was able to set up the automation steps to find the corresponding lists from the bonus plan and staff list. I have tried AI to get the script but it is not iterating each item from the input list. I also want to input the value year-month from the previous step of automation so that the created record already has year-month linked.
Essentially I am looking for the following output:
Jane / Bonus Plan A / 2025-03
Jane / Bonus Plan B / 2025-03
Jane / Bonus Plan C / 2025-03
Ben / Bonus Plan A / 2025-03
Ben / Bonus Plan B / 2025-03
Ben / Bonus Plan C / 2025-03
Script is as follows:
// Access input variables from previous automation steps
const inputConfig = input.config();
const bonusPlanNames = inputConfig.bonusPlanNames;// Array of Bonus Plan names (primary field)
const staffNames = inputConfig.staffNames;// Array of Staff names (primary field)
const yearMonth = inputConfig.yearMonth;// String in "YYYY-MM" format
console.error(`Staff record not found: ${staffName}`);
continue;
}
// Create a new record in the Bonus Records table
await bonusRecordsTable.createRecordAsync({
"bonusplan":#{ id: bonusPlanRecord.id }],// Link to the Bonus Plan record
"stafflist":#{ id: staffRecord.id }],// Link to the Staff record
"Year-Month": yearMonth // Set the Year-Month field
});
console.log(`Created record for Bonus Plan: ${bonusPlanName}, Staff: ${staffName}, Year-Month: ${yearMonth}`);
}
}
console.log("All records created successfully!");
I have the input list set as following:
Hope to figure this out, thank you so much!!
Page 1 / 1
I would probably just use a repeating group on the first list of records. Then ask chatgpt to write you a script to process that one record and match it with another record in your second table (depending on how you want to match the records). Then create a record in your third table which links to the first two. This way you ensure each record is processed and chatgpt can write a simpler script.