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’)