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:
You have two options when adding the JavaScript Code for this expression:
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();
}
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.
If you've added this Custom Property, you can use it in other areas. For example: