Help

Adding 'Assigned To' to a new task!

Topic Labels: Scripting extentions
1867 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Shayda_Haddad
4 - Data Explorer
4 - Data Explorer

Hello!

My team uses airtable for our task tracking. We get new clients/shows all the time and many of them start off with the same tasks. I used one of the examples to help get me started on some basics! I would like to add another line under each field that allows me to assign a member of my team to a certain task. Does anyone know how to do this and/or if this is possible? This is what I have so far…

Thanks so much for your feedback on this!

`// pick tables from your base here

let tasks = base.getTable(‘Task’);
let projects = base.getTable(‘Performances’);
// prompt the user to pick a template for our project
output.markdown(’# New Show’);
let name = await input.textAsync(‘Task’);
// create the project - change the field name to one in your base
let projectId = await projects.createRecordAsync({
‘Performance’: name,
});
// create the tasks - change the field names to ones from your base.
// the [{id: projectId}] links the newly created records back to our project
await tasks.createRecordsAsync([
{
fields: {
‘Task’: ‘Pixel Check: TM Artist/Event’,
‘Show Name’: [{id: projectId}],
’Assigned To’:
},
])
output.text(‘Done!’);`

1 Reply 1
Stephen_Suen
Community Manager
Community Manager

Hey @Shayda_Haddad,

To write to a single collaborator field, you need to pass in an object with the user id. You can get all of the collaborators for a base via base.activeCollaborators. One way to make this easier to consume is to construct a mapping:

let collaboratorIdByName = {};
for (let collaborator of base.activeCollaborators) {
    collaboratorIdByName[collaborator.name] = collaborator.id;
}

This object maps collaborator names to ids. You could also use collaborator.email as the key, especially if a base has multiple collaborators with the same name. Once you have this mapping, you can do the following:

await tasks.createRecordsAsync([
    {
        fields: {
            ‘Task’: ‘Pixel Check: TM Artist/Event’,
            ‘Show Name’: [{id: projectId}],
            ’Assigned To’: {id: collaboratorIdByName[name]},
        },
    },
])

You can read more about the cell formats and field options here: Airtable Scripting