DEFINES
  • 2 Minutes to read
  • Dark
    Light
  • PDF

DEFINES

  • Dark
    Light
  • PDF

Article summary

Script Variables (DEFINES)

Script variables (also known as DEFINES) work in a similar way to System Variables in that they allow scripts to be developed with variable input.

Unlike System Variables, Script Variables are WRITE-ONCE/READ.   The content of a Script Variable is calculated prior to script execution and must be set up in the DEFINES section of a script.

Defines Method

{
  "method": "Defines",
  "variables": [
    {
      "key": "%key%",
      "value": "value"
    }
  ],
  "onError": {
    "email": [
      ""
    ],
    "message": "script failed"
  },
  "project": "Test
}


"method": "Defines"

Definitions of script variables and error processing

"variables": [

    {

      "key": "%key%",

      "value": "value"

    }

  ],

Key/value pairs. 

key:  the variable name, must start and end with % 

value: the value to put in place of the key whenever it is found in script. 

Up to 256 key/value pairs can be added to variables. 

  "onError": {

    "email": [

      ""

    ],

    "message": "script failed"

  },

Sets up error handling notifications for the script.

Email: Email addresses to notify via email if an error occurs 

Message: Message content

Adding Defines to a script

To add a DEFINES section to a script, go to Script Editor | Tools | Defines and a method will be added to the current script.

(Note:   it is possible to add more than one DEFINES section to a script)

DEFINES take the following format:

{
  "method": "defines",
  "variables": [
    {
      "key": "",
      "value": ""
    }
  ],  
  "project": "TESTPROJECT"
}

Multiple key/value pairs can be defined in the same DEFINES method:

key

The name of the Script Variable/Define. 

Must start and end with a % 

e.g.,     %MyVariable%

value

The value to be stored in the variable. 

Note – this value cannot be changed anywhere else in the script.  

All Script and System Variables are RESOLVED before the script is executed.   This means that all occurrences of the Variable within the script are replaced with the RESOLVED VALUE before script processing starts.

When editing a script, to view the RESOLVED VALUES of variables, use CTRL L to bring up the Script Variables Dialog:

Embedded Defines

It is possible for both key and value to contain both Script Variables and System Variables.   

Consider the following: 

 {
 "method": "defines",
  "variables": [
    {
      "key": "%JOB_NAME%",
      "value": "Job 0001"
    },
    {
      "key": "%PROCESSING_FOLDER%",
      "value": "%DATAPATH%ETL_Output/"
    },
    {
      "key": "%OUTPUT_FOLDER%",
      "value": "%PROCESSING_FOLDER%%JOB_NAME%/Output"
    }

  ],  
  "project": "TESTPROJECT"
}

%OUTPUT_FOLDER% will be resolved to:

%DATAPATH%ETL_Output/Job 0001/Output

(Note that the Script Variables window does not show the resolved value of %DATAPATH% or any other System Variable.   This is by design.  Only users who have access to the server hard-drive are able to determine the paths of System Variables.)

Using Defines in a script

Defines can be used in all script methods apart from Expressions.  If a Variable is used in a script but has not been setup in a DEFINES section, the unresolved value will be kept and the script will still be executed. 

e.g., 

"filename": "%OutputFile_New%"
{
  "method": "IF",
  "condition": "%StartRow%==0 && %EndRow%==0",
  "project": "Test5"
}
{
  "method": "SaveDataSetAsField",
  "name": "DS_RowsToProcess",
  "dataSet": {
    "logic": "or",
    "name": "DS_RowsToProcess",
    "strict": true,
    "set": [
      {
        "logic": "and",
        "stype": "FIELD",
        "entity": {
          "type": "field",
          "name": "01_DATA_IN.ExcelRow",
          "table": "01_DATA_IN",
          "valueFilter": []
        },
        "op": "between",
        "values": [
          "%StartRow%",
          "%EndRow%"
        ]
      }
    ]
  },
  "project": "Test5"
}



Was this article helpful?

What's Next