Renaming Field Values Dynamically Using JavaScript

In this example we will be using this sample dataset:

STS_CD STS_DSCP
SS Success

Here, the STS_CD field holds the status code, while STS_DSCP contains the description. The requirement is to rename the description so that when STS_CD equals “SS”, the value of STS_DSCP should display “Successful” instead of “Success”.

Steps to Implement:

  1. Open your report template in Repertoire Designer.

  2. Locate the target field that you want to rename. In this example we will be using the field “STS_DSCP”:

  3. Double click it to open up the properties window. Change the field type to Script.

  4. Attach the script below to the field’s script property.

// Retrieve the data source named "Default" into variable x
var x = DataCacheManager.getCache("Default");

// Define the string value we want to use when renaming
var y = "Successful";

// Check if the field STS_CD from the data source equals "SS"
if (x.getString("STS_CD") == "SS") {
//Set y as the new value.
    y;
}
  1. Save the template and render it; the output should now look like this:
    image