Loading

Topics

Available on Asana Enterprise and Enterprise+ tiers. You must have edit access to the project to create or modify rules.

You can automatically log time entries in Asana by using script actions within project Rules to programmatically record duration when a task moves to a specific section.

Automating time tracking ensures that your team's effort is captured accurately without the manual overhead of logging minutes for every routine task. By leveraging script actions within Asana Rules, you can programmatically create time entries—for instance, logging 15 minutes of "Quality Assurance" time whenever a task enters the "Testing" section.

Note iconNote

API limitation: The Asana API allows you to create, retrieve, and delete time entries. However, it does not support starting or stopping the live timer (the "Play/Pause" button) programmatically.

How to automate time entries using script actions

  1. Open your project and click Workflow in the top-right corner
  2. Select Rules and choose Create custom rule
  3. Set the Trigger to "Task moved to section"
  4. Set the Action to "External action" and select Run script
  5. Enter your JavaScript code into the editor

Automating time tracking with the Timesheets and budgets Add-on

If your organization has the Timesheets and budgets add-on, you have access to extended metadata. This allows you to define if the time is billable and add a specific description to the entry.

Script example:

JavaScript

async function run() {

  // Make an API request to get the triggered task and wait for the response

  const task = await tasksApiInstance.getTask(task_gid);

  // Print the task's name to see it in the run history.

  log("task's current name: " + task.data.name);

  let body = {

  "data": {

    "duration_minutes": 15,

    // Attribute to the parent project

    "attributable_to": task.data.projects[0]?.gid ??  null,

    "billable_status": "billable",

    "description": "Automatic log: Section transition processing",

  }

};




  await timeTrackingEntriesApiInstance.createTimeTrackingEntry(body, task_gid).then((result) => {

    log("API called successfully. Returned data: " + JSON.stringify(result.data, null, 2));

}, (error) => {

    log(JSON.stringify(error.response.body));

});




}

// The script must end with returning a Promise via run().

run();

Automate without timesheets and budgets add-on

On Advanced or Enterprise tiers without the Timesheets add-on, you can still automate time logging. While you cannot set a "billable" status or a description, you can successfully log the duration to the task.

Script example:

JavaScript

async function run() {

  // Make an API request to get the triggered task and wait for the response

  const task = await tasksApiInstance.getTask(task_gid);

  // Print the task's name to see it in the run history.

  log("task's current name: " + task.data.name);

  let body = {

  "data": {

    "duration_minutes": 15,

  }

};


  await timeTrackingEntriesApiInstance.createTimeTrackingEntry(body, task_gid).then((result) => {

    log("API called successfully. Returned data: " + JSON.stringify(result.data, null, 2));

}, (error) => {

    log(JSON.stringify(error.response.body));

});


}

// The script must end with returning a Promise via run().

run();

Capabilities comparison

Feature

Timesheets & budgets add-on

Standard time tracking

Log Duration

✅ Supported

✅ Supported

Add Description

✅ Supported

❌ Not Supported

Set Billable Status

✅ Supported

❌ Not Supported

Attributed Project

✅ Supported

❌ Not Supported

Optimization and debugging

To ensure reliable script performance and accurate data logging, follow these technical requirements and best practices:

  • Project settings: You must add the Time Tracking field to your project settings before running the script; failure to do so results in a script error because the data has no destination.
  • Debugging methods: Use console.log() to output variables during the setup phase. You can view script logs within the Rule History tab to confirm that the script is successfully receiving the intended taskGid.
  • Dynamic time: Instead of hardcoding duration = 20, you can pull the value from a custom field on the task using context.task.custom_fields.
Learn iconLearn

For further technical exploration, refer to the Asana Developer Documentation for Time Tracking.

Loading
Article Detail