Skip to main content
Liaison

Isolating Individual Test Scores

By default, when you include test scores in an export or the Application Summary, Outcomes displays all instances of that test. If you're more interested in collecting just one result (e.g., the most recent, highest, or average test score), you can use a JavaScript expression to isolate that value.

In this article, you'll learn to apply JavaScript to a custom property or an export field that allows you to distill multiple test scores into one value. This can be used in connection with ACTs,  GMATs, MCATs, SATs, or other tests that can have multiple values.

Add the JavaScript Code

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

  • 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. The code you'll use is dependent on what you want to isolate:

  • Highest test score
  • Most recent test score
  • Average test score

If the test has multiple sections, you'll need to create a separate field for each section. For example, one field for the GRE quantitative score, and another for the GRE verbal score.

Code for the Highest Test Score

To apply this configuration to pull the highest test score, 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.)

// This function returns a number or blank
// It evaluates the highest values captured for a specific number column from a table

function getHighestValue(form_name, table_key, number_field_key) {
    
    if (forms?.[form_name]?.[table_key]?.rows?.length > 0) {    
    
        let highest = forms?.[form_name]?.[table_key]?.rows[0]?.[number_field_key];    
        for (let i = 0; i < forms?.[form_name]?.[table_key]?.rows?.length; i++) {            
            if (forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key] >= 0) {                
                if (forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key] > highest) {                    
                    highest = forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key];
                }
            }
        }
        if (highest != null) {
            return highest;
        } else {
            return "";
        }
    } else {
        return "";
    }
}

 After dropping in this code, you'll need to update the variables so that it will work with the test of your choice and only pull in the scores in your desired range. Review the guidance below for more details.

Code for Most Recent Test Score

To apply this configuration to pull the highest test score, 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.)

// This function returns a number or blank
// It evaluates the most recent date from a table

function getMostRecentValue(form_name, table_key, number_field_key, date_field_key) {
    
    if (forms?.[form_name]?.[table_key]?.rows?.length > 0) {
    
        let mostRecentValue = forms?.[form_name]?.[table_key]?.rows[0]?.[number_field_key];
        let mostRecentDate = forms?.[form_name]?.[table_key]?.rows[0]?.[date_field_key];
        
        for (let i = 0; i < forms?.[form_name]?.[table_key]?.rows?.length; i++) {            
            if (forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key] >= 0) {                
                if (forms?.[form_name]?.[table_key]?.rows[i]?.[date_field_key] > mostRecentDate) {                                            
                    mostRecentDate = forms?.[form_name]?.[table_key]?.rows[i]?.[date_field_key];
                    mostRecentValue = forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key];
                }
            }
        }
        if (mostRecentValue != null) {
            return mostRecentValue;
        } else {
            return "";
        }
    } else {        
        return "";
    }
}

 After dropping in this code, you'll need to update the variables so that it will work with the test of your choice and only pull in the scores in your desired range. Review the guidance below for more details.

Code for Average Test Score

To apply this configuration to pull the highest test score, 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.)

// This function returns a number or blank
// It evaluates the average of values captured for a specific number column from a table

function getAverageValue(form_name, table_key, number_field_key) {
    
    let total = 0;
    let count = 0;
    
    if (forms?.[form_name]?.[table_key]?.rows?.length > 0) {    
    
        for (let i = 0; i < forms?.[form_name]?.[table_key]?.rows?.length; i++) {            
            if (!isNaN(forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key]) && forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key] >= 0) {                
                total += forms?.[form_name]?.[table_key]?.rows[i]?.[number_field_key];
                count++;
            }
        }
        if (count > 0) {
            return total / count;
        } else {
            return "";
        }
    } else {
        return "";
    }
}

 After dropping in this code, you'll need to update the variables so that it will work with the test of your choice and only pull in the scores in your desired range. Review the guidance below for more details.

Updating the Variables

For this expression to work in your environment, you'll need to replace the variables at the top of the code snippet. After adding the code into the Expression window, identify the variables and update them to indicate which test score you'd like to extract.

Depending on which code you are using, the first line of code has either three or four variables for you to work with. These include:

  • form_name - replace this variable with the key of the form where the test results are collected. For example, standardized_tests.
  • table_key - replace this variable with the key of the table that contains the test results you need. For example, gmat.
  • number_field_key - replace this variable with the key of the specific field that you're working with. For example, gmat_quantitative.
  • date_field_key - replace this variable with the key of the date field related to the test you're working with. For example, gmat_date.

For more details, review Finding the Keys to Use.

Finding the Keys to Use

The test scores you need are typically stored in an applicant form. Within the form, the details of each test, including scores, dates, and other relevant information, might be captured in a table. Review the steps below to modify the code to work with tests that are stored in a table.

  1. Replace form_name with the key associated with the form that you are pulling the score from. As an example, if you were pulling results from the form in the example below, gradeScores (found in the Key field at the top of the form) would be the appropriate name to use.

    Sample applicant form using named rows
  2. Replace table_key with the key from the table you want to use. In the example above, satoptional is the key you would use.
  3. Replace number_field_key with the key from the column you want to use. To find the key, click the column heading of the column that contains your test scores. In the window that appears, note the Key field on the right. In the example above, you'd click the Evidence-Based Reading and Writing column heading to bring up the column details, including the satEvidenceBasedReadingAndWriting key, as seen below.

    Sample column heading key
  4.  For the most recent test score code, replace date_field_key with the key from the date field column. In the example above, you'd click the Exam Date column heading to bring up the column details, including its key.

     For the most recent test, with the updates from this example, the editable area of the code would appear as follows:

function getMostRecentValue(gradeScores, satoptional, satEvidenceBasedReadingAndWriting, examDate) 
  1. After modifying the expression, click Update to save your work.

Note that, if you'd like to pull in multiple values from the same test, you'll need to create another field to isolate that value. For example, in the example above, you could create a field that collects the highest math score, and another that collects the highest reading and writing score.

Testing the Code

While building the export or your calculated property, click the Try It button to confirm that your variables are working.

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

This article corresponds with JSO-17.

 

  • Was this article helpful?