GET - custom_field.multi_enum_value

Hello!

I’m using Python and I am wondering if there is a way to get a gid value of a multi enum field selection.

Currently I have been using custom_fields.display_value however when I want to POST the display_value to another task I noticed that the param needs to contain the gid of the custom field as well as the key of the value where all I am able to GET is the value name.

Am I missing something or is this simply not a functionality and I’d have to figure out a way to match the display name to the key on the client side?

Thanks!

Hello everyone,

I took care of this on the client side however I’ll leave the topic open in case anyone else runs into the same issue.

Hi @Andy_Pilipovic,

Glad you figure this out. For the folks who stumble across this post, you can access the gid of the selected enum values for a multi-select enum custom field by asking for the custom_fields.multi_enum_values in the opt_fields query params.

Context:
custom_fields.multi_enum_values → if your custom field is a multi_enum type (i.e., 'resource_subtype': 'multi_enum') this contains information about the enum_values that was selected.

custom_fields.display_value → regardless of custom_field type this will return the text value of that custom field

custom_fields.enum_options → if your custom field is a multi_enum type (i.e., 'resource_subtype': 'multi_enum') this will return the available enum options for that multi-select custom field.

Here’s what the usage might look like for the python client (v3.2.2):

import asana
from pprint import pprint

client = asana.Client.access_token("<YOUR_PERSONAL_ACCESS_TOKEN>")
task_gid = "<YOUR_TASK_GID>"

result = client.tasks.get_task(task_gid, fields="custom_fields.name,custom_fields.display_value,custom_fields.multi_enum_values,custom_fields.enum_options")
pprint(result)

This is an example response from the code above:

{'custom_fields': [{'display_value': 'Option 1',
                    'enum_options': [{'color': 'green',
                                      'enabled': True,
                                      'gid': '<ENUM_OPTION_1_GID>',
                                      'name': 'Option 1',
                                      'resource_type': 'enum_option'},
                                     {'color': 'red',
                                      'enabled': True,
                                      'gid': '<ENUM_OPTION_2_GID>',
                                      'name': 'Option 2',
                                      'resource_type': 'enum_option'}],
                    'gid': '<CUSTOM_FIELD_GID>',
                    'multi_enum_values': [{'color': 'green',
                                           'enabled': True,
                                           'gid': '<ENUM_OPTION_1_GID>',
                                           'name': 'Option 1',
                                           'resource_type': 'enum_option'}],
                    'name': 'Multi-Select'}],
 'gid': '<TASK_GID>'}

Notice that multi_enum_values has extra information for the value in the display_value and notice that enum_options returns the available enum_options for this specific multi-select custom field.

You can apply this opt_fields trick with Get multiple tasks endpoint as well.

EX:

import asana
from pprint import pprint

client = asana.Client.access_token("<YOUR_PERSONAL_ACCESS_TOKEN>")
project_gid = "<YOUR_PROJECT_GID>"

result = client.tasks.get_tasks({"project": [project_gid]}, fields="custom_fields.name,custom_fields.display_value,custom_fields.multi_enum_values,custom_fields.enum_options")
pprint(list(result))

TIP: Look at the full schema of the resource that is being returned to understand what values you can request for in the opt_fields EX: if you are making calls to Get multiple tasks, Get a task you can look at the full task schema and read about the properties that is available.

Another trick is to look at the listed options in opt_fields drop down for those endpoints.

EX:

Thanks for clarifying @John_Vu :mechanical_arm:

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