Context (Execution)
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(): LongReturns the iteration number of the current execution as a Long.
Context.getIteration(); // returns iteration numberstatic getNodeId(): String
static getNodeId(): StringUse this method to retrieve the unique node identifier as a String.
Context.NodeId(); // returns ID of current nodestatic getStartedBy(): JsonNode
static getStartedBy(): JsonNodeReturns the data associated with the user user who started the workflow.
Context.getStartedBy(); // returns JSON objectstatic getCreatedBy(): JsonNode
static getCreatedBy(): JsonNodeReturns the data associated with the user who created the workflow.
Context.getCreatedBy(); // returns JSON objectstatic environment(): String
static environment(): StringThis method returns the environment in which the workflow is executed, such as "development" or "production."
Context.environment();static isProd(): Boolean
static isProd(): BooleanUse 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 booleanstatic isDev(): Boolean
static isDev(): BooleanSimilarly, you can check if the current environment is "development" using this method. It returns true for development environments and false otherwise.
Context.isDev(); // returns booleanstatic configs(): JsonNode
static configs(): JsonNodeThis 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 objectstatic stats(): JsonNode
static stats(): JsonNodeReturns statistical data in the form of a JSON node, allowing you to access execution statistics.
Context.stats(); // returns JSON objectstatic getExecutionId(): String
static getExecutionId(): StringRetrieve the execution ID as a String. This can be useful for tracking and logging purposes.
Context.getExecutionId();static getName(): String
static getName(): StringObtain 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();static sleep(Long: millis): void (Experimental)
static sleep(Long: millis): void (Experimental)In this example the iteration will wait 5 seconds without blocking the main thread
Context.sleep(Long.parseLong("5000"));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?