Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Garconis/f7a079229a0b239b13c5a11dc4f6953e to your computer and use it in GitHub Desktop.
Save Garconis/f7a079229a0b239b13c5a11dc4f6953e to your computer and use it in GitHub Desktop.
Asana | Rule > Script editor > add tag to task
/**
* What's in scope?
* 1. (string) project_gid, workspace_gid, task_gid (only if triggered on a task)
* 2. (function) log - this behaves like console.log and takes any number of parameters
* 3. (object) *ApiInstance - for each group of APIs, an object containing functions to call the APIs; for example:
* tasksApiInstance.getTask(...)
* goalsApiInstance.addFollowers(...)
* For more info, see https://github.com/Asana/node-asana
*/
async function run() {
// 1. Get the task, including permalink_url
const task = await tasksApiInstance.getTask(
task_gid,
{ opt_fields: "name,permalink_url" }
);
log("✅ Task: " + task.data.name + " (" + task.data.permalink_url + ")");
// 2. Add the tag (by GID)
const tagToAdd = "123456789";
await tasksApiInstance.addTagForTask(
{ data: { tag: tagToAdd } },
task_gid
);
log(`🏷️ Added tag ${tagToAdd} to task ${task_gid} (${task.data.permalink_url})`);
// 3. Post a comment (story) on the task
const storyRequestBody = {
data: {
text: `Script triggered: added tag ${tagToAdd}`
}
};
await storiesApiInstance.createStoryForTask(
storyRequestBody,
task_gid
);
log(`💬 Comment added to task ${task_gid}`);
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment