Created
April 21, 2025 19:25
-
-
Save Garconis/f7a079229a0b239b13c5a11dc4f6953e to your computer and use it in GitHub Desktop.
Asana | Rule > Script editor > add tag to task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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