Javascript baby here.
My ultimate goal is that when a record is created and matches conditions, a script will run that will duplicate that record a number of times and update it's status. I've been modifying a duplication script from an extension script, but I'm a bit stuck on how to make it work for an automation, and if I'm even doing the right thing. If you have a moment to take a look, I would really appreciate it!
Here is the code as it stands:
let table = base.getTable("🏁 Tasks")
let fields = table.fields
let query = await table.selectRecordsAsync({fields: table.fields})
let records = query.records
//I have a set number of records that will need to be duplicated based on information from the base which I think should be inputConfig.numRecords
let inputConfig = input.config();
//exluding only one field
let exclude = ["Dependent On"]
let filteredFields = fields.filter(x => !exclude.includes(x.name) && x.isComputed == false)
//I'm not sure if I need this part if it's being triggered by an automation instead of an extension
let original = await input.recordAsync("Original Record", table)
//Here is my attempt to have the script create multiple duplicated records based on a number from the base
for (let i = 0; i < inputConfig.numRecords; i++) {
let obj = {};
filteredFields.map(x => {
Object.assign(obj, {[x.name]: original.getCellValue(x.name)})
})
//I want it to set the field "Reoccuring Task" to "Duplicated", not sure if this is right
obj["Reoccurring Task?"] = "Duplicated";
await table.createRecordAsync(obj)
In the past, I've used make (integromat) to solve for this sort of thing, and I'm sure it could do so very easily, but I'm trying to learn and grow 😊