Skip to main content
Liaison

Converging Race/Ethnicity Selections Into One Field

While completing the biographic section of their application, applicants typically have the option to select as many races and ethnicities as they deem appropriate. When working with this data or importing it into another system, you may wish to distill the applicants' selections down to one field.  In this article, you'll learn to apply a JavaScript expression that assesses the applicants' selections and pulls one response into a custom property.

This expression follows federal guidelines as follows:

  • If an applicant reports as Hispanic, the field returns Hispanic, even if other races/ethnicities are selected.
  • If an applicant reports any single race (other than Hispanic) the field returns the single race selection. This includes:
    • Native American
    • Asian
    • Hawaiian or Pacific Islander
    • Black
    • White
  • If an applicant selects more than one of the races above, but not Hispanic, the field returns Two or More. Note that if an applicant selects two or more subcategories under the same category, the field returns only the higher category (e.g., if an applicant selects Asian along with the Indian and Pakistani subcategories, the field returns Asian).
  • Lastly, if an applicant reports nothing, the field returns Did Not Report.

Add the JavaScript Code

You have two options when adding the JavaScript Code for this expression:

  • Create a Custom Property using this code. Once created, Custom Properties are listed among the Available Fields in the Export Builder.
  • Add the JavaScript expression directly from the Export Builder by selecting the Custom option from the Available Fields menu, and dropping it into the Columns window.

In either case, you'll have an Expression area to add your code and configure it as desired.

To apply this configuration, in the Expression area, add the following code. This snippet results in one field that displays a value as described above. (Use the view source icon at the top right to copy the code snippet.)

{
    function getRaceEthnicity() {
        
        if ((forms) &&
            (forms.race_ethnicity)) {        
            
            if ((forms.race_ethnicity.hispanic) && a
                (forms.race_ethnicity.hispanic != null) &&
                (forms.race_ethnicity.hispanic == "Yes")) {
                return "Hispanic";
                    
            } else if ((forms.race_ethnicity.hispanic_sub) &&
                (forms.race_ethnicity.hispanic_sub.length > 0)) {
                return "Hispanic";
                    
            } else if ((forms.race_ethnicity.race) &&
                (forms.race_ethnicity.race.length > 0)) {
                
                if ((forms.race_ethnicity.race.length > 1)) {
                    return "Two or More";
                    
                } else if ((forms.race_ethnicity.race.length == 1)) {
                    
                    let raceArray = forms.race_ethnicity.race;
                    
                    if (((forms.race_ethnicity.asian_sub == null)
                            || ((forms.race_ethnicity.asian_sub) && (forms.race_ethnicity.asian_sub.length < 1))) &&
                        ((forms.race_ethnicity.pac_island_sub == null)
                            || ((forms.race_ethnicity.pac_island_sub) && (forms.race_ethnicity.pac_island_sub.length < 1)))) {
                        switch(raceArray[0]) {
                            case("White"): return "White";
                            case("American Indian or Alaska Native"): return "Native American";
                            case("Asian"): return "Asian";
                            case("Black or African-American"): return "Black";
                            case("Native Hawaiian or Other Pacific Islander"): return "Hawaiian or Pacific Islander";
                        }
                        
                    } else if ((forms.race_ethnicity.asian_sub) &&
                        (forms.race_ethnicity.asian_sub.length > 0)) {
                        
                        if (((forms.race_ethnicity.pac_island_sub) &&
                                (forms.race_ethnicity.pac_island_sub.length > 0)) ||
                            (raceArray[0] != null && raceArray[0] != "Asian")) {
                            return "Two or More";
                        } else {
                            return "Asian";
                        }
                        
                    } else if ((forms.race_ethnicity.pac_island_sub) &&
                        (forms.race_ethnicity.pac_island_sub.length > 0)) {    
                        
                        if ((raceArray[0] != null && raceArray[0] != "Native Hawaiian or Other Pacific Islander")) {    
                            return "Two or More";
                        } else {    
                            return "Hawaiian or Pacific Islander";
                        }
                    }
                }
            } else if ((forms.race_ethnicity.asian_sub) &&
                (forms.race_ethnicity.asian_sub.length > 0)) {
                    
                if ((forms.race_ethnicity.pac_island_sub) &&
                    (forms.race_ethnicity.pac_island_sub.length > 0)) {
                    return "Two or More";
                    
                } else {
                    return "Asian";
                }
            } else if ((forms.race_ethnicity.pac_island_sub) &&
                (forms.race_ethnicity.pac_island_sub.length > 0)) {    
                return "Hawaiian or Pacific Islander";
                
            } else {
                return "Did Not Report";
                
            }
        } else {
            return "";
        }
    }
    
    return getRaceEthnicity();
}

Testing the Code

While building the Custom Property or export, click the Try It button at the bottom right of the Expression window to confirm that your adjustments are working.

Search for a record to complete your tests with. Confirm that the appropriate value appears in the Output window.

Working with Race/Ethnicity Custom Properties

If you've added this Custom Property, you can use it in other areas. For example:

  • In Exports: The field will become available in the Export Builder to include in your exports.
  • On Applications: The field becomes available to add to the Application Summary for quick viewing.
  • On the Applications Grid Header: You can customize your Applications Grid to include the fields of your choice, including Custom Properties.
  • In Filters: You can add filters to your Applications Grid to isolate specific ethnicities.
  • Was this article helpful?