Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Record template from record picker

Topic Labels: Scripting extentions
Solved
Jump to Solution
286 1
cancel
Showing results for 
Search instead for 
Did you mean: 

Hallo,
i have a problem with the script.
i would like a template with next actions for a project with record picker function.
but the problem is with my script, i have two projects with the same name always after the script.
one project is empty and one projects with the template actions.
Problem is the projectid var. The script create always a new record.
Can someone help me pls with the syntax?

// pick tables from your base here
let projects = base.getTable(‘Projekte’);
let tasks = base.getTable(‘Next Action’);
// prompt the user to pick a template for our project

output.markdown(’# New project’);

let record = await input.recordAsync(‘Select a record to use’, projects);

if (record) {
// Customize this section to handle the selected record
// You can use record.getCellValue(“Field name”) to access
// cell values from the record
output.text(You selected this record: ${record.name});
let projectId = await projects.createRecordAsync({
‘Projekte’: record.name,
});
await tasks.createRecordsAsync([
{
fields: {
‘Next Action’: ‘The first task’,
‘Projekte’: [{id: projectId}],
},
},
{
fields: {
‘Next Action’: ‘Another task’,
‘Projekte’: [{id: projectId}],
},
},
{
fields: {
‘Next Action’: ‘The final task’,
‘Projekte’: [{id: projectId}],
},
}
])
output.text(‘Done!’);
} else {
output.text(‘No record was selected’);
}

1 Solution

Accepted Solutions

hi @mkay232,
the problem you are facing here is that you are using as project id the id of the new project that the script is creating. Basically the script creates a new project and then creates the tasks with as connected project the one you just created. What you instead want, is to have the script select an existing project and then add the id of that project to the new tasks you create.
To do that replace this:

let projectId = await projects.createRecordAsync({
‘Projekte’: record.name,
});

with

let projectId = record.id

Hope this helps!

Website: alessiomonino.com
Calendly: Calendly - Alessio Monino
Email: alessio.monino@gmail.com

See Solution in Thread

1 Reply 1

hi @mkay232,
the problem you are facing here is that you are using as project id the id of the new project that the script is creating. Basically the script creates a new project and then creates the tasks with as connected project the one you just created. What you instead want, is to have the script select an existing project and then add the id of that project to the new tasks you create.
To do that replace this:

let projectId = await projects.createRecordAsync({
‘Projekte’: record.name,
});

with

let projectId = record.id

Hope this helps!

Website: alessiomonino.com
Calendly: Calendly - Alessio Monino
Email: alessio.monino@gmail.com