In your instance of Outcomes, you may have translation tables that convert the value in an application property to something else, making it work with your exports. If you have multiple programs with a similar question, these questions will be collected under different application properties. As a result, you may want to create a new field that collects all of these properties, runs them through a translation table, and then produces a final value based on what it finds.
In this article, you'll learn to create an exportable field that looks at various properties and applies the translation of your choice. For this to work, the following should already be in place:
Once this is in place, this advanced configuration will help you create an application or export property that implements the needed translation and collects the final value in a single field.
For this step, begin building a custom property using the Calculated property type. In the Expression window, paste the JavaScript code below. Then, you'll need to replace all of the variables in the code and duplicate the relevant snippet so that it will work in your environment. Alternatively, you can add this code directly into an export by selecting the Calculated option under Available Fields.
Create a calculated custom property. Add the following code into the Expression window. Hover over the window below and click the view source button at the top right to copy the code.
{ let conditionField1 = yourfield1; let conditionField2 = yourfield2; if (program.name.includes("1") && conditionField1 != ""){ return translate(conditionField1,'Translation Table 1') } else if (program.name.includes("2") && conditionField2 != ""){ return translate(conditionField2,'Translation Table 2') } else { return ''; } }
Next, you'll need to replace the variables in the code with fields that are relevant to your desired result.
The variables included in the code snippet above are as follows:
Where needed, use the Field Dictionary to find the appropriate field names.
Next, where applicable, you'll need to add additional lines of code to account for more programs that you need to work with, as described below.
As written, the sample code works in situations where there are only two programs that need to be considered. For each additional program, you'll need to:
else if (program.name.includes("2") && conditionField2 != ""){
return translate(conditionField1,'Translation Table 1')
}
Place this line of code before the else { line. Continue adding this snippet and updating its variables until you've accounted for all the programs that you want to work with this code.
Once complete, your code may look similar to the following:
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.
To include this custom property in an export, in the Available Fields area, find the custom property you created above and add it to the Columns window.
As an alternative, you could add a Calculated field in your export, and paste the code listed above into the Expression field.