How to obtain the selected custom field value from a project in a protfolio?

I’ve been trying to get to the actual selected values of my custom fields but seems like I can only get the existing fields but not their values?

i.e. Using Python:

create an instance of the API class

api_instance = asana.CustomFieldSettingsApi(asana.ApiClient(configuration))

project_gid = ‘MYPROJECT_GID’
opt_fields = [“custom_field.name.display_value”]

try:
# Get a project’s custom fields
api_response = api_instance.get_custom_field_settings_for_project(project_gid, opt_fields=opt_fields)
pprint(api_response)
except ApiException as e:
print(“Exception when calling CustomFieldSettingsApi->get_custom_field_settings_for_project: %s\n” % e)

I get this:

{'data': [{'custom_field': {'asana_created_field': None,
                            'created_by': None,
                            'currency_code': None,
                            'custom_label': None,
                            'custom_label_position': None,
                            'date_value': None,
                            'description': None,
                            'display_value': None,
                            'enabled': None,
                            'enum_options': None,
                            'enum_value': None,
                            'format': None,
                            'gid': '1205091168333886',
                            'has_notifications_enabled': None,
                            'is_formula_field': None,
                            'is_global_to_workspace': None,
                            'is_value_read_only': None,
                            'multi_enum_values': None,
                            'name': 'Priority',
                            'number_value': None,
                            'people_value': None,
                            'precision': None,
                            'resource_subtype': None,
                            'resource_type': None,
                            'text_value': None,
                            'type': None},
           'gid': '1205091168333892',
           'is_important': None,
           'parent': None,
           'project': None,
           'resource_type': None},
          {'custom_field': {'asana_created_field': None,
                            'created_by': None,
                            'currency_code': None,
                            'custom_label': None,
                            'custom_label_position': None,
                            'date_value': None,
                            'description': None,
                            'display_value': None,
                            'enabled': None,
                            'enum_options': None,
                            'enum_value': None,
                            'format': None,
                            'gid': '1205091168333899',
                            'has_notifications_enabled': None,
                            'is_formula_field': None,
                            'is_global_to_workspace': None,
                            'is_value_read_only': None,
                            'multi_enum_values': None,
                            'name': 'Status',
                            'number_value': None,
                            'people_value': None,
                            'precision': None,
                            'resource_subtype': None,
                            'resource_type': None,
                            'text_value': None,
                            'type': None},
           'gid': '1205091168333906',
           'is_important': None,
           'parent': None,
           'project': None,
           'resource_type': None},
          {'custom_field': {'asana_created_field': None,
                            'created_by': None,
                            'currency_code': None,
                            'custom_label': None,
                            'custom_label_position': None,
                            'date_value': None,
                            'description': None,
                            'display_value': None,
                            'enabled': None,
                            'enum_options': None,
                            'enum_value': None,
                            'format': None,
                            'gid': '1205091168333914',
                            'has_notifications_enabled': None,
                            'is_formula_field': None,
                            'is_global_to_workspace': None,
                            'is_value_read_only': None,
                            'multi_enum_values': None,
                            'name': 'Effort level',
                            'number_value': None,
                            'people_value': None,
                            'precision': None,
                            'resource_subtype': None,
                            'resource_type': None,
                            'text_value': None,
                            'type': None},
           'gid': '1205091168333920',
           'is_important': None,
           'parent': None,
           'project': None,
           'resource_type': None}],
 'next_page': None}

Ideally I’d like to get the values selected for:

  • ‘name’: ‘Priority’
  • ‘name’: ‘Status’
  • ‘name’: ‘Effort level’

Any ideas?
Thanks in advance!

In Asana, “custom field settings” refers to the definition of what custom fields are configured to belong to a project or portfolio; it’s only related to the configuration, not to any actual data of objects in that portfolio or project.

To get the actual values of custom fields in a project, you’ll want to use this endpoint:

2 Likes

Hi @David171,

@Phil_Seeman is right. If you want to get the actual values of the custom fields in your project you’ll want to call our Get a project endpoint.

Here’s how you would do that with our python client library (v4.X.X):

import asana
from asana.rest import ApiException
from pprint import pprint

# Configure access token
configuration = asana.Configuration()
configuration.access_token = '<YOUR_PERSONAL_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# Create a project API Instance
project_api_instance = asana.ProjectsApi(api_client)

# Query params
project_gid = "<YOUR_PROJECT_GID>"
opt_fields = ["custom_fields"]

try:
    # Get a project
    api_response = project_api_instance.get_project(project_gid, opt_fields=opt_fields)
    pprint(api_response.data.custom_fields)
except ApiException as e:
    print("Exception when calling ProjectsApi->get_project: %s\n" % e)

Here’s what the result would look like from running the above code. NOTE: this result is from having a single select custom field on the project so yours will probably look different:

[{'date_value': None,
 'display_value': 'CF Option 1',
 'enabled': True,
 'enum_options': [{'color': 'green',
                   'enabled': True,
                   'gid': '<ENUM_OPTION_1_GID>',
                   'name': 'CF Option 1',
                   'resource_type': 'enum_option'},
                  {'color': 'red',
                   'enabled': True,
                   'gid': '<ENUM_OPTION_2_GID>',
                   'name': 'CF Option 2',
                   'resource_type': 'enum_option'}],
 'enum_value': {'color': 'green',
                'enabled': True,
                'gid': '<ENUM_OPTION_1_GID>',
                'name': 'CF Option 1',
                'resource_type': 'enum_option'},
 'gid': '<CUSTOM_FIELD_GID>',
 'is_formula_field': False,
 'multi_enum_values': None,
 'name': 'This is a custom field',
 'number_value': None,
 'resource_subtype': 'enum',
 'resource_type': 'custom_field',
 'text_value': None,
 'type': 'enum'}]

In this example the selected value for the single select custom field for this project is:

 'enum_value': {'color': 'green',
                'enabled': True,
                'gid': '<ENUM_OPTION_1_GID>',
                'name': 'CF Option 1',
                'resource_type': 'enum_option'},

2 Likes