1. Home
  2. Matador Extensions
  3. Asana Integration
  4. Implementing Enum Custom Fields

Implementing Enum Custom Fields

Enum fields in Asana can be very useful for limiting the values that can be put in a field, and ensuring your data remains clean and useable. However, due to the way values need to be set for enum fields in Asana, mapping your form data to the enum options does require a little custom code.

First you’ll need to get the GID values for your custom enum field and all its options. You can do this by opening up your Asana project and clicking the little arrow to the right of the Project title. Then select ‘Export’, then ‘JSON’:

Once the file has downloaded, open it up and look for the name of your enum field:, it should be listed under ‘custom_fields’

Now you’ve got all the GID numbers, it’s time to add your enum custom field, and the value you want to set it to in Asana, to the array of custom fields used in the extension code.

Below you’ll find an example of detecting if the form submission concerns a candidate, or a hiring company, and reflecting this in an enum field on Asana:

<?php 

add_filter( 'matador_asana_task_prepared_custom_fields', 'matador_example_add_enum_custom_field', 10, 3 );

function matador_example_add_enum_custom_field( $custom_fields, $data, $context ) {

    $filtered_custom_fields = $custom_fields;

    /**
     * The following 3 id numbers must be formatted as strings for Asana to accept them. 
     * They must also correspond exactly to the gid numbers in your Asana project/workspace 
     * 
     * If they do not correspond they will be filtered out before the task is created to
     * prevent the task creation from failing entirely
     */

    // The gid of my 'Type' custom field in Asana
    $my_enum_field_gid = "9382756432109485";

    // The gid of my 'Employer' enum option for my 'Type' field in Asana
    $employer_enum_option_gid = "5647382910564738";

    // The gid of my 'Candidate' enum option for my 'Type' field in Asana
    $candidate_enum_option_gid = "7823645189052716";
    
    // The gid of my 'Other' enum option for my 'Type' field in Asana
    $other_enum_option_gid = "3501974826758391";
    
    // The WordPress ID of the application retrieved from the application data
    $wpid = $data['wpid'];

    if ( ! empty( $wpid ) ) {

        // Retrieving the submission type from the post meta
        $contact_type = get_post_meta( $wpid, "_matador_submission_type", true );
        
        switch ($contact_type) {
            case 'application':
                $field_value_to_set = $candidate_enum_option_gid;
                break;
            case 'contact':
                $field_value_to_set = $employer_enum_option_gid;
                break;
            default:
                $field_value_to_set = $other_enum_option_gid;
                break;
        }

        $filtered_custom_fields[ $my_enum_field_gid ] = $field_value_to_set;
    }

    return $filtered_custom_fields;
}
Updated on June 25, 2024
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support