Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Apr 08, 2022 04:22 PM
Hi there,
New to the community, you guys have already been a huge help. So I borrowed a script from this user: Creating Tasks from a Template
and then I adapted the code into an automation I am building. What I am trying to do is this:
Via Automation
When a Record is created use that record as the selectedEvent (instead of choosing a selected even like Victoria has in her script) and then run the script.
Victoria’s script asks you to choose the template for the linked tasks, but I figured out how to set it to one set of tasks by using the id of that template in the code.
Below is the code I’ve been using in my automation script and I keep getting this error: Error: Field “fldtxrU67I4FayPzK” cannot accept the provided value.
I think my problem is I’m not entering the correct object when I create the list of tasks. I think this has to do with my syntax when referring to an object using the record id. Any help would be appreciated. Thank you all!!
// Declare variables for views from the projects table here
let table = base.getTable(“Planning Check List”)
let templateProjects = base.getTable(‘Projects’).getView(‘Template Projects’)
//Pull in the variables from Step 1 of the automation
//let inputConfig = input.config();
//let myRecord = inputConfig.theProject
const inputConfig = input.config()
const myRecord = inputConfig[“theProject”]
let selectedEvent = myRecord
// pick tables from your base here
let checklist = base.getTable(‘Planning Check List’)
let templateView = base.getTable(‘Planning Check List’).getView(‘Template View’);
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = await templateQuery.records.filter( t => t.getCellValue(‘Project’)[0].id == ‘recZu9rmZhFT96MjP’);
//Set the status for new items to “Not Started”
let initialStatus = “Not Started”
console.log(selectedEvent)
// create the tasks
// the [{id: projectId}] links the newly created records back to our project
let createRecords = templateRecords.map( c => ({fields: {
'Name': c.getCellValue('Name'),
'Project': [selectedEvent],
//'Project': {id:theID}
'Project Progress': {name: initialStatus}
}})
);
//if({id:myRecord})await checklist.createRecordsAsync(createRecords)
await checklist.createRecordsAsync(createRecords)
//else output.markdown("# Uh-Oh You didn’t select an event!")
Apr 08, 2022 08:22 PM
The formatting of the forum makes it hard to read you code and we don’t see the value of your input variables, so I’m not sure what format you are using. I suggest you use console.log(createRecords)
just before the line where you create the records so that you can see the exact format that you are using. The proper format for a linked record field needs to be an array of objects, where the object has a key of “id” and a value of the internal record id of the record to be linked.
If you still need help, can you post screen shots that include the value of the input variable, the error, and the fields in question?
Apr 10, 2022 03:20 PM
1st off, I’m so glad that you replied, I’ve learned so much from your replies to other questions.
2nd, here is a scren screenshots of my code with the output from the console.log(createRecords)
3rd here is the code properly formatted, I figured out how to post it properly
// Declare variables for views from the projects table here
let table = base.getTable("Planning Check List")
let templateProjects = base.getTable('Projects').getView('Template Projects')
//Pull in the variables from Step 1 of the automation
//let inputConfig = input.config();
//let myRecord = inputConfig.theProject
const inputConfig = input.config()
const myRecord = inputConfig["theProject"]
let selectedEvent = myRecord
// pick tables from your base here
let checklist = base.getTable('Planning Check List')
let templateView = base.getTable('Planning Check List').getView('Template View');
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = await templateQuery.records.filter( t => t.getCellValue('Project')[0].id == 'recZu9rmZhFT96MjP');
//Set the status for new items to "Not Started"
let initialStatus = "Not Started"
console.log(selectedEvent)
// create the tasks
// the [{id: projectId}] links the newly created records back to our project
let createRecords = templateRecords.map( c => ({fields: {
'Name': c.getCellValue('Name'),
'Project': [selectedEvent],
//'Project': {id:theID}
'Project Progress': {name: initialStatus}
}})
);
//if({id:myRecord})await checklist.createRecordsAsync(createRecords)
console.log(createRecords)
await checklist.createRecordsAsync(createRecords)
//else output.markdown("# Uh-Oh You didn't select an event!")
Apr 10, 2022 06:37 PM
Thanks for letting me know that you find my posts useful.
You didn’t post screenshots of your fields, but I am guessing that your ‘Project’ field is a linked record field. Linked records need to be set as an array of objects. The format is documented here. Try this for line 31.
'Project': [{id: selectedEvent}],
Apr 11, 2022 06:57 AM
Sorry here are the screenshots you requested, and here is a screenshot of the errors I got when I tried the recommended code.
Apr 14, 2022 12:14 PM
Hi, just wanted to follow up.
Apr 14, 2022 12:21 PM
I do not have the time to troubleshoot this for your now for various private reasons.
If you want me to set aside time to look at this, I recommend booking a meeting with me.