Question about Asana_AI's script

I have a script that works properly.
I asked Asana_AI to fix any problems with the script.
They changed it as follows.
However, the script doesn’t work properly after the change.


Asana_AI says: Yes, there is a problem with this part of the script. I will fix it.
Problem
Incorrect argument order: The correct argument order for the updateTask method is task ID first, then update data.
task_gid variable is undefined: The script defines REFERENCE_TASK_GID variable, but does not use task_gid.


-Before: “// update task with event date set to due date
updateBody.data.custom_fields[fieldGid] = { date: taskData.due_on };
try {
await tasksApiInstance.updateTask(updateBody, task_gid);
}”

-After: “// update task with event date set to due date
updateBody.data.custom_fields[fieldGid] = { date: taskData.due_on };
try {
await tasksApiInstance.updateTask(REFERENCE_TASK_GID, updateBody);
}”



Original post: I tried using AI in rules. - #4 by Stephen_Li

@Ka_Nishiyama - I think the issue is that for scripts actions (in rules), the environment comes pre-loaded with task_gid, which is set as the gid of the task triggering the rule. That’s why that variable works without being explicitly defined in the script (it’s defined in the environment in the background).

I assume that Asana AI doesn’t automatically know this context, so it just sees an undefined variable and tries to “fix” that. Based on the documentation and the fact that it works as expected, I think you can revert to the original.

1 Like

@Stephen_Li
I gave the AI the entire script and asked it to “fix any problems,” but is that not a good way to ask?

Maybe you could also prompt it with the context that comes with the script (I didn’t include it in the original):

/**
* 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
*/
1 Like

I asked both Gemini and Copilot to fix any problems.
They tried to fix it, but none of it worked.


AI_Studio consumes credits. I thought it would be a breeze if I asked Asana_AI to create a script, but unfortunately it didn’t work.