fieldmap
Update your data extract table by combining existing values into new or existing columns.
This guide explains how to configure the fieldmap instruction. To learn about another instruction, go back to the Available custom script instructions overview.
Introduction
Use the fieldmap instruction to update the data extract table by inserting values from existing columns into new or existing columns. You can use Python expressions to create new values.
Any columns that are not included in this instruction will be removed from your data extract.
Creating a custom script transformation using the fieldmap instruction
To create and configure a custom script using the fieldmap instruction, follow these steps:
-
In the Instructions step, select the fieldmap instruction.
-
To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).
-
Mapping
-
Enter the mapping to update your table. Click + to add in another set of mapping fields. Fill in the following fields:
-
Output field
-
Enter a name for the new column to be added to the data extract. This column will contain the new, mapped values.
-
Input field
-
Enter the name of the column that contains the values with which to populate the new columns. Choose one of the following options from the drop-down field to the left of the Input field:
-
String - Select this option and enter the name of the column in the original data extract. The values from this column are used to populate the new column
-
Python - Select this option and enter a python expression to use only the values that catch the criteria of the expression. For more information on python expressions in custom scripts, see Using Python expressions in custom scripts.
-
-
-
Fail on Error
-
Enter the value with which to populate the field if an error occurs.
-
Error value
-
Enter the value with which to populate the field if an error occurs.
-
Subtable
-
Enter the name for a subtable that you want to use within this custom script.
A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.
If a subtable does not exist for the current custom script, the transformation is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the transformation and optionally as the output.
Example
Transformation configuration
In this example, we want to combine the values in our Campaign and Ad Group columns into a single column called Advert. The two original columns will be removed from the data extract.
We want to keep the values in our Clicks column as they are. However, if we do not include the Clicks column in the transformation instruction, it will be removed from the data extract. As a result, we need to include this column, and we can simply keep its name the same.
-
Mapping 1
-
Output field =
Advert
-
Input field (Python) =
{Campaign} + "-" + {Ad Group}
-
Mapping 2
-
Output field =
Clicks
-
Input field (String) =
Clicks
-
ErrorValue
-
Error
Data table before transformation
Campaign |
Ad Group |
Clicks |
---|---|---|
Brand |
media |
7 |
Brand |
ecommerce |
3 |
Dashboard |
media |
|
Dashboard |
media|social |
5 |
Data table after transformation
Advert |
Clicks |
---|---|
Brand - media |
7 |
Brand - ecommerce |
3 |
Dashboard - media |
Error |
Dashboard - media|social |
5 |