A Server Variable is used to store values such as text, numbers, email addresses, or any reusable data, and access them across scripts. This helps improve maintainability by avoiding hardcoded values in multiple places.
Instead of updating values in every script, you can update the value in the server variable once, and the change will automatically reflect wherever it is used.
Example:
If multiple scripts use the same email address, you can create a server variable named support_email.
- Use the variable in scripts instead of hardcoding the email
- If the email changes, update it in the server variable
- All scripts will automatically use the updated value
This ensures consistency and reduces maintenance effort.
Scope of Server Variables
Server variables support two scopes:
- Global: Use this when the value is common across the application
- Accessible across all scripts
- Same value is used everywhere
- Example: Support email, API base URL
- Script: Use this when the value varies based on the script
- Accessible only in selected scripts
- Allows different values for each script
- Example: Memory limits, thresholds, or environment-specific values
Create a Server Variable
- Navigate to
(settings) >> CodeX >> click Server Variables in the menu. - Click the New Variable button.
- Provide the following details:
- Name : Enter a name for the variable.
- Description : Provide a description for the variable.
- Scope : Choose a scope type for the variable.
- Global - Available across all scripts
- Value: Enter a value for the variable
- Script - Available only in selected scripts
- Script: Select the scripts where you want to use the variable
- Script Values : Enter the value for each selected script
- Click Save.
Using Server Variables in Scripts
You can access a server variable inside a script using:
ZDK.Vars.getScriptVariable("<variable_name>");
Example:
var count = ZDK.Vars.getScriptVariable("SDK_Count");
This retrieves the value based on:
- Global value (if scope is Global)
- Script-specific value (if scope is Script)