Skip to main content
Liaison

Combine Multiple Fields Into One

When extracting data from Outcomes, you may need to combine two or more fields, creating a single exportable field. This may be useful if you are importing data into another system that requires specific data points to be included in one field. For example, you may want to concatenate each applicant's Program Start Term and Program Start Year.

Using this configuration, you can select up to five fields you'd like to combine, and choose what delimiter (if any) you'd like to use in between each data point. The steps to complete this configuration are as follows:

  1. Determine which fields need to be combined, and find the corresponding field keys using the Field Dictionary.
  2. Add a function to the Function Library that serves to apply the JavaScript needed for this configuration.
  3. Create an export using a Calculated Field that references your function and lists the fields you wish to include.

Add a Function to Your Function Library

The Function Library in Outcomes is a tool that allows you to add JavaScript Expressions to be used as functions when exporting data or creating Custom Properties.

To add this configuration to your Function Library:

  1. Navigate to your Function Library and click on the Default Function Set.

    function-library-page.png
  2. Click into the Contents field and add the following JavaScript expression at the end of the existing code. (Use the view source icon at the top right to copy the code snippet.)
function mapIsNullOrUndefined(field) {

    try {
        if (field == null || typeof field == "undefined") {
            return "";
        }
    } catch (e) {
        return "";
    }
    return field;
}

function concatString(delimiter, field1, field2, field3, field4, field5) {
    let ignoreList = ["ignore"];
    let initialValue = "";

    if (delimiter == null || delimiter == "") {
        delimiter = " | ";
    }

    let fieldArray = [field1, field2, field3, field4, field5];

    let concatFields = fieldArray
        .filter((field) => {
            return ignoreList.includes(field) ? false : true;
        })
        .map((field) => {
            return mapIsNullOrUndefined(field);
        })
        .reduce((previousValue, currentValue, index, array) => {
            if (index == array.length - 1) {
                return previousValue + currentValue
            }
            return previousValue + currentValue + delimiter;
        }, initialValue);

    return concatFields;
}
  1. Click Save Changes.

Now that you've added this function, you can apply it in your Exports.

Building Your Export File

To complete this configuration, you'll need to build an export using a Calculated Property that references the function listed above. To do this:

  1. Navigate to the Exports page and add a new Export, or edit an existing one.
  2. Add a Calculated Property.

    adding-calculated-property-to-export.png
  3. After dropping a Calculated Property into the Columns area, a Field Expression window appears. In the Expression field, paste the following code. (Use the view source icon at the top right to copy the code snippet.)
{
    /* USER INPUT SECTION */
    let delimiter = " | ";
    let field1 = field.key.for.first.field;
    let field2 = field.key.for.second.field;
    let field3 = field.key.for.third.field.if.any;
    let field4 = field.key.for.fourth.field.if.any;
    let field5 = "ignore";

    /* DO NOT EDIT */
    return concatString(delimiter, field1, field2, field3, field4, field5);
}
  1.  Next, replace the let fieldX = variables with the field keys you wish to use.

    add-concatenate-field-expression.png
  2. The code allows for up to five fields to be concatenated. If you are combining fewer than five fields, replace the unneeded field keys with "ignore" as seen above (let field5 = "ignore";) In the example above, there are four fields in use:
    • forms.race_ethnicity?.hispanic_sub;
    • program.properties?.program_standardizedtestscorerequirement;
    • program.properties?.program_campus;
    • forms.gender_identity?.gender_identity_response;
  3. Next, choose the delimiter you want to use to separate the data from each field. In the example above the delimiter is set to a pipe (|). To use another delimiter, replace the pipe character in the let delimiter = " | "; line. Other delimiter options include:
    • comma (,)
    • underscore (_)
    • hyphen / dash (-)
    • exclamation mark / bang (!)
    • blank space ( )
  4. To test that the code works, click Try It and select an applicant to test with.
  5. To apply a name to this Calculated Property, type the name in the Label field.
  6. Click Update to save your expression.

In the resulting export, the fields you listed are combined into one field.

  • Was this article helpful?