Need some help with updating custom_field.multi_enum_values

I’ve been working with Asana’s API in Python, I’ve ran into a problem that I cannot figure out.

I am trying to update a Custom field on a task, the field is a multi enum value.
I am passing the custom field gid and the multi enum value gid however I cannot get it to update.
I’ve tried using the API explorer and tried to update it from there however I’m still not getting any good outcomes.

This is what the code looks like, any ideas where I’m going wrong?

task_gid_input = (‘1205636205887937’)
task_gid = (‘1205837604911113’)

input = client.tasks.get_task(task_gid_input,
opt_fields = {‘custom_fields.display_value’}, opt_pretty=True)
print(input)

print(‘done’)

stages_to_check_for = [‘4. Site Inspection needed’, ‘5. Site Inspection Scheduled’, ‘6. Site Inspection Completed’, ‘07. 2nd Site Inspection Scheduled’, ‘15. Engineering in Progress’, ‘16. Pending HOA’, ‘17. Plan Ready’, ‘18. Engineering Revisions’, ‘20. Ready for Permit’, ‘21. Pending Permit’, ‘22. Permit Received’, ‘23. HI/MPU in Progress’, ‘24. Installation in Progress’, ‘25. Installation Complete’, ‘26. Final Inspection Pending’, ‘27. Final Inspection Received’, ‘30. Pending PTO’, ‘31. PTO Received’, ‘33. Places in Service’, ‘Lost’]

Extract the ‘display_value’ from custom fields

custom_fields = input.get(‘custom_fields’, )
display_value = None

for field in custom_fields:
if field.get(‘display_value’) in stages_to_check_for:
display_value = field.get(‘display_value’)
break

stages = {
“4. Site Inspection needed”: “1205176507759394”,
“5. Site Inspection Scheduled”: “1205176507759395”,
“6. Site Inspection Completed”: “1205176507759396”,
“07.2nd Site Inspection Scheduled”: “1205176507759397”,
“15. Engineering in Progress”: “1205176507759398”,
“16. Pending HOA”: “1205176507759399”,
"17. Plan Ready ": “1205176507759400”,
“18. Engineering Revisions”: “1205176507759401”,
“20. Ready for Permit”: “1205176507759402”,
“21. Pending Permit”: “1205176507759403”,
“22. Permit Received”: “1205176507759404”,
“23. HI/MPU in Progress”: “1205176507759405”,
"24. Installation in Progress ": “1205176507759406”,
"25. Installation Complete ": “1205176507759407”,
"26. Final Inspection Pending ": “1205176507759408”,
“27. Final Inspection Received”: “1205176507759409”,
"30. Pending PTO ": “1205176507759410”,
"31. PTO Received ": “1205176507759411”,
“33. Places in Service”: “1205176507759412”,
“Lost”: “1205176507759413”}

Print the ‘display_value’

if display_value is not None:
print(f"The display value for task GID {task_gid_input} is: {display_value}“)
else:
print(f"No ‘display_value’ found for task GID {task_gid_input}”)

display_value_output = stages[display_value]

print(display_value_output)

#result = client.tasks.update_task(task_gid,
#params={“1205176507759393”: ‘“’ + (display_value_output) + ‘”’}, opt_pretty=True)

custom_field_gid = ‘1205176507759393’
custom_field_value = display_value_output

result = client.tasks.update_task(
task_gid,
params={custom_field_gid: custom_field_value},
opt_pretty=True
)

print(‘done’)

Hi @Andy_Pilipovic,

Here’s how you update a multi-select custom field with python (v3.2.2)

import asana
from pprint import pprint

client = asana.Client.access_token("<YOUR_PERSONAL_ACCESS_TOKEN>")
task_gid = "<YOUR_TASK_GID>"
custom_field_gid = "<YOUR_MULTI_SELECT_CUSTOM_FIELD_GID>"
multi_select_enum_value = "<YOUR_MULTI_SELECT_ENUM_VALUE_GID>"

result = client.tasks.update_task(
    task_gid, 
    {'custom_fields': {custom_field_gid: multi_select_enum_value}}
)
pprint(result)

NOTE: you should not be providing the display_value as the value for updating the value of a multi-select custom field. Instead provide the enum_gid of the value of the multi-select_enum option. You can get information about the available enum options for your multi-select custom field by asking for custom_fields.enum_options in your Get a task API call.

2 Likes

@John_Vu you are a gift <3

That worked. I was also able to post while providing the display_value as it holds the gid of the multi enum field that it finds in the dict.

Thanks once again, this has been pestering me for the past 24 hours :smiley:

2 Likes

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