DynamicDefines
  • 3 Minutes to read
  • Dark
    Light
  • PDF

DynamicDefines

  • Dark
    Light
  • PDF

Article summary

Run Time Script Variables (DynamicDefines)

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

Unlike DEFINES, DynamicDefines are evaluated as the script processes.   The content of a Dynamically Defined Script Variable therefore depends on the conditional execution path of the script

A variable can be defined as part of a DEFINES method and then over-written using DynamicDefines.  The same variable can be over-written many times in the same script.

DynamicDefines Method

{
  "method": "DynamicDefines",
  "variables": [
    {
      "key": "%key%",
      "value": "value"
    }
  ],     
  "project": "Test
}


"method": "DynamicDefines"

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. 

Adding DynamicDefines to a script

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

1 - Remove the onError element:

Change the method name to be DynamicDefines and add in variable key-pairs:

"onError": {
    "email": [
      ""
    ],
    "message": "script failed"
  },

2 - Change the method name to be DynamicDefines and add in variable key-pairs:

{
  "method": "DynamicDefines",
  "description": "Set values as multiple of 1",
  "variables": [
    {
      "key": "%Var1%",
      "value": "1"
    },
    {
      "key": "%Var2%",
      "value": "10"
    },
    {
      "key": "%Var3%",
      "value": "defaultString"
    }
  ],
  "project": "LargeDataSource"
}

Multiple key/value pairs can be defined in the same DynamicDefines 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 declared using the DEFINES method are RESOLVED before the script is executed.   This means that all occurrences of those variable within the script are replaced with the RESOLVED VALUE before script processing starts.

When editing a script, the RESOLVED VALUES of static variables (created using DEFINES) can be seen using CTRL L to bring up the Script Variables Dialog:

Script Variables Window
The script variables window will not display resolved values for DynamicDefines as these are not known until the script is processed.


Sample Script

The following is an example of DynamicDefines:

[
  {
    "method": "Defines",
    "description": "Passed variables",
    "variables": [
      {
        "key": "%Control1%",
        "value": "99"
      }
    ],
    "onError": {
      "email": [
        ""
      ],
      "message": "script failed"
    },
    "project": "LargeDataSource"
  },
  {
    "method": "IF",
    "condition": "%Control1%==1",
    "project": "LargeDataSource"
  },
  {
    "method": "remark",
    "text": "Default execution path if no variables passed in",
    "project": "LargeDataSource"
  },
  {
    "method": "LogWrite",
    "text": "Using default control variables",
    "project": "LargeDataSource"
  },
  {
    "method": "DynamicDefines",
    "description": "Set values as multiple of 1",
    "variables": [
      {
        "key": "%Var1%",
        "value": "1"
      },
      {
        "key": "%Var2%",
        "value": "10"
      },
      {
        "key": "%Var3%",
        "value": "defaultString"
      }
    ],
    "project": "LargeDataSource"
  },
  {
    "method": "ELSE",
    "project": "LargeDataSource"
  },
  {
    "method": "remark",
    "text": "Alternative execution path if over-ride variables supplied",
    "project": "LargeDataSource"
  },
  {
    "method": "LogWrite",
    "text": "Using over-ride control variables",
    "project": "LargeDataSource"
  },
  {
    "method": "DynamicDefines",
    "description": "Set values as multiple of %Control1%",
    "variables": [
      {
        "key": "%Var1%",
        "value": "%Control1%"
      },
      {
        "key": "%Var2%",
        "value": "%Control1%0"
      },
      {
        "key": "%Var3%",
        "value": "overrideString"
      }
    ],
    "project": "LargeDataSource"
  },
  {
    "method": "ENDIF",
    "project": "LargeDataSource"
  },
  {
    "method": "LogWrite",
    "text": "Dynamic Variables: Var1=%Var1%, Var2=%Var2%",
    "project": "LargeDataSource"
  },
  {
    "method": "remark",
    "text": "Self-checking of DynamicDefines",
    "project": "LargeDataSource"
  },
  {
    "method": "IF",
    "condition": "%Control1%==1 && %Var1%=",
    "project": "LargeDataSource"
  },
  {
    "method": "StopWithError",
    "text": "Dynamic Defines not set correctly",
    "project": "LargeDataSource"
  },
  {
    "method": "ENDIF",
    "project": "LargeDataSource"
  }
]

Was this article helpful?

What's Next