UpdateTask not working in Asana (Desktop App) rule for Run Script Action

I’m at wit’s end here. I need to update a custom field, but the script keeps failing whenever it tries to run tasksApiInstance.updateTask(). The script can successfully run getTask(), getTasksForProjects(), and other API calls, but for some reason not updateTask().

Here’s the code I’m using in the rule’s Run script action:

Blockquote
let taskBody = {‘data’: {‘custom_fields’: {“1234” : “2012-12-12”}}};

const updateTask = await tasksApiInstance.updateTask(JSON.stringify(taskBody), “1234”);
Blockquote

Here’s the error: " Cannot read properties of undefined (reading ‘hasOwnProperty’) "

Any help would be greatly appreciated!

Welcome to the forum, @Marcellus_Stewart! Could you post a code snippet? You can fix your specific error by not stringifying taskBody in your update call. Beyond that, from your example, if you’re trying to update a date, I think you’ll need to wrap a date field in another object with a property "date".

So the whole script would be like:

const main = async () => {
    const update = {
        "data": {
            "custom_fields": {
                // date
                "123": { date: "2025-05-21" },

                // text
                "321": "test"
            },
        },
    };

    await tasksApiInstance.updateTask(update, task_gid);

};

main();
2 Likes

Thanks soooo much! Adding {date: …} and removing JSON.stringify() did the trick! I can’t thank you enough!!! I’ve got a big deadline coming up, so thank you, thank you!

2 Likes

For anyone struggling with using a variable’s value for an object’s key, please refer to JavaScript’s object literal notation. For my issue above, I needed to use a variable to plug-in the custom field’s id:

let taskBody = {
‘data’: {
‘custom_fields’: {
[custom_field_gid] : { date: “2025-05-21” }
}
}
};

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.