A Row Level Code transformation applies python code to each row of data to transform the input values into the output that will be placed in the output field for that row.
Prerequisites
- You must have Manage Data Mappings permission.
- A syntactic mapping should have already been created.
Creating a Row Level Code Transformation
To create a Row Level Code transformation, complete the following steps.
Step 1: Open the Transformations Panel
- In the Syntactic Mappings page, choose the mapping you want to edit.
- Click the Edit Pencil in the Transformation field for the entry you would like to edit transformations for.
- The Transformations Panel will appear. Click the Add Transformation button.
- Click the dropdown menu to select the desired transformation type.
- Select the Row Level Code transformation.
Step 2: Fill in the Transformation Configuration
- Note the Source Input and Target Output. It should reflect what you already chose in the syntactic mapping entry.
- Enter a Python code snippet that you want to apply to each row.
- The code snippet has access to the input fields in a special "row" variable. This is a dictionary with each field name mapped to the field value. For example, if there is a "gender" source field, your code can access its value for the input row via:
row["gender"]
- The code snippet should set the desired output value to a special "output" variable. For example, if you'd like to take the input value of the "gender" field, and set the output to be the first letter of the input value in uppercase, your code could look like this:
output = row["gender"][:1].upper()
- The code snippet has access to the input fields in a special "row" variable. This is a dictionary with each field name mapped to the field value. For example, if there is a "gender" source field, your code can access its value for the input row via:
- Indicate what happens if the code fails (e.g. there is an exception when executing the code). You have three options:
- Skip row - this entire row is omitted from the output.
- Fail - the Data Harmonization code run fails - you will see the error message in the detailed log of the code run.
- Set to default - set a specific value (e.g. "" or "ERROR") to the output value in rows in which the error occurred. If you select to set to a default value, a new input appears that allows you to enter the default value. The value can be a string or a number.
- When complete, click the Save button.
Ordering Transformations
When code runs, configured transformations are executed one after another. If you want to change the order of transformation execution for specific syntactic mapping entries, complete the following steps.
- In the Syntactic Mapping page, choose the mapping you want to modify.
- Select the Edit Pencil in the Transformation field for the entry you want to edit. The Transformations Panel will appear.
- Click the transformation's handle (six domino-looking dots), and drag the transformation in the order you want it to run. Do this for each transformation that you want to reorder.
- When done, click Save at the bottom of the page.
Editing a Transformation
To edit a transformation, complete the following steps.
- In the Syntactic Mappings page, select the mapping that you want to edit transformations for.
- Find the mapping entry you want to edit, then click the pencil icon in the Transformation column. The Transformations Panel will appear.
- Edit the transformation as desired.
- When complete, click the Save button.