Jul 17, 2020 11:52 AM
I manage online content for items sold at retail. I have a record for each UPC (item). Every UPC will have updates done 1x a month. I have a checkbox field that indicates when the item has been updated on the retailer’s website.
I would like to have a NEW record created automatically, once the checkmark box is selected. This new record should have some of the values prepopulated based off of the original record. Each record has a date for “update due”, which is 30 days from the last update.
Ultimately, in a year, I would have 12 records for one UPC, each with the original content changes in their respective fields.
Just not sure how to have the system automatically create a new record. Haven’t had luck with scripting block (am admittedly a newby), and zapier only offers me the option of creating a new record when another new record is created.
With hundreds of UPCs to update monthly, automating this would be a HUGE time saver!
Jul 17, 2020 12:12 PM
One option you might pursue would be using a Button field and the Scripting Block. You could have a Update
button that when clicked, fills in the checkbox and runs a script to duplicate that record. Here’s a script that may do what you want:
let table = base.getTable("Table Name")
let query = await table.selectRecordsAsync()
let records = query.records
let fields = table.fields
// List the names of all the fields you want pre-populated when a record is copied
let populate = ["Field 1", "Field 2"]
let filteredFields = fields.filter(x => populate.includes(x.name) && x.isComputed == false)
let original = await input.recordAsync("Original Record", table)
let obj = {}
filteredFields.map(x => {
let fieldValue = original.getCellValue(x.name)
let method = fieldValue && x.type=="multipleRecordLinks" ? fieldValue.map(y => ({id: y.id})) : fieldValue
Object.assign(obj, {[x.name]: method})
})
await table.createRecordAsync(obj)
await table.table.updateRecordAsync(original, {
"Checkbox Field Name": true,
})
This assumes your {Update Due}
field is taken care of by a formula (i.e. DATEADD(CREATED_TIME(), 30, 'days')
)
Jul 17, 2020 10:14 PM
Another option is to have a script (like the one that @Kamille_Parks wrote, or possibly a variant of it) triggered using the new scripting action beta. Marking a checkbox in a record could make that record appear in a specific view, which could then trigger the script. The script could also clear the checkbox once it’s done, resetting it for the next time it’s needed. The benefit to this method is that the sidebar won’t open like it would when triggering a script with a button. It all happens behind the scenes.