---
sourceDocument: Xanadu ServiceNow AI Platform Administration
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/platform-administration

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu ServiceNow AI Platform Administration

ft:clusterId :

    - platadm

bundleId :

    - platadm

workflow :

    - Platform


---

# Create a script for a transform definition

# Create a script for a transform definition {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

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.
{#t_CreateAScriptForATransformDef__ul_gkj_nvc_dr}

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

|-|-|
| 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). |
[Table 1. Position parameters]

{#t_CreateAScriptForATransformDef__table_mvr_c1d_dr}

## 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.  
3. Update the record to complete the configuration.  
   The Odd/Even transform definition is now ready to use in a field
   transformation.

