Context Class
Learn how to access various runtime context information.
The Context
class provides access to various runtime context information, allowing you to interact with the environment and retrieve essential data. Using this class, you can access the current running execution.
Note: Context Class will not be available when workflow is stopped.
Methods
static getIteration(): Long
static getIteration(): Long
Returns the iteration number of the current execution as a Long
.
Context.getIteration(); // returns iteration number
static getNodeId(): String
static getNodeId(): String
Use this method to retrieve the unique node identifier as a String
.
Context.NodeId(); // returns ID of current node
static getStartedBy(): JsonNode
static getStartedBy(): JsonNode
Returns the data associated with the user user who started the workflow.
Context.getStartedBy(); // returns JSON object
static getCreatedBy(): JsonNode
static getCreatedBy(): JsonNode
Returns the data associated with the user who created the workflow.
Context.getCreatedBy(); // returns JSON object
static environment(): String
static environment(): String
This method returns the environment in which the workflow is executed, such as "development" or "production."
Context.environment();
static isProd(): Boolean
static isProd(): Boolean
Use this method to determine if the current environment is "production." It returns true
if the script is running in a production environment; otherwise, it returns false
.
Context.isProd(); // returns boolean
static isDev(): Boolean
static isDev(): Boolean
Similarly, you can check if the current environment is "development" using this method. It returns true
for development environments and false
otherwise.
Context.isDev(); // returns boolean
static configs(): JsonNode
static configs(): JsonNode
This method provides access to configuration data in the form of a JSON node. You can use it to retrieve and manipulate configuration settings.
Context.configs(); // returns JSON object
static stats(): JsonNode
static stats(): JsonNode
Returns statistical data in the form of a JSON node, allowing you to access execution statistics.
Context.stats(); // returns JSON object
static getExecutionId(): String
static getExecutionId(): String
Retrieve the execution ID as a String
. This can be useful for tracking and logging purposes.
Context.getExecutionId();
static getName(): String
static getName(): String
Obtain the name associated with the execution context as a String
. This may be a human-readable identifier or a descriptive name for the execution context.
Context.getName();
The Context
class empowers your custom scripts to access critical information about the runtime environment and the current execution context, making it a valuable tool for building versatile and context-aware applications.
Examples
Example: Accessing Runtime Context Information.
// Check the current environment
var isProduction = Context.isProd();
var isDevelopment = Context.isDev();
var environmentStatus = "Current Environment: ";
if (isProduction) {
environmentStatus += "Production";
} else if (isDevelopment) {
environmentStatus += "Development";
} else {
environmentStatus += "Unknown";
}
// Get information about the execution
var executionId = Context.getExecutionId();
var executionName = Context.getName();
// Display the collected information
var executionInfo = "Execution ID: " + executionId + "\nExecution Name: "
+ executionName;
var contextInfo = environmentStatus + "\n\n" + executionInfo;
return contextInfo;
Was this helpful?