Create the script at any time during the configuration of a definition.

About this task

The script can perform a transform action without using a variable, but the action of the definition will be the same for all fields. Variables create more flexibility for the definition, enabling an administrator to use the same definition in different ways in different places. If a variable is defined, the script must reference the variable using the correct format.

There are three arguments in the script:
  • Variables: Contains the variables using the format variables.<variable name>.
  • Value: Contains the un-transformed value
  • Parameters: Special objects that set debug messages.

All position parameters (such as Starting position and Ending position) have three modes that apply to all the transform types that use this variable.

Table 1. Position parameters
Positive positions If the position is expressed as a positive integer, the platform calculates the starting position beginning from the left side of the field value. For example, in the string ABCDE, a position of 3 places the starting point of the action after C.
Negative positions If the position is expressed as a negative integer, the platform calculates the position beginning from the right side of the field value. For example, in the string ABCDE, a position of -3 places the starting point of the action before C.
Regex If the position value starts with /regex/, everything after that is a regular expression that is used to calculate the starting position. For example, in the string ABCDE, a position of /regex/B.*D places the starting point of the action after C (B and all the characters between B and D).

Procedure

  1. Open the Odd/Even record in the Transform Definitions module.
  2. Enter the following script to pass values with the odd_even variable.
    function(variables, value, parameters) {
    	var odd = ('odd' == variables.odd_even);
    	var val = value - 0;
    	var val_odd = ((val & 1) == 1);
    	if (odd != val_odd)
    		val++;
    	return '' + val;
    	}

    The script references the variable in the form variables.odd_even.

    Column named referenced in variable
  3. Update the record to complete the configuration.

    The Odd/Even transform definition is now ready to use in a field transformation.