All Articles

How to Find the Execution Initiation Mode while the Process is Being Executed

Processes are executed in many different ways. A few examples are Test Mode, Schedule, or a Schedule Retry. It is possible to get the execution method while the process is executing and using a decision or route shape to the document flow differently based on the execution method. The code below will be set within a Data Process shape. The script is used to set a dynamic process properties. Then a Decision or Route shape can be used route the flow of the documents to different paths.

The Groovy script uses three getter methods to get information on the execution method and the information is added to the process logs. Then an if/else should be used to set a standard output. Finally, a dynamic process property is set to be used later in the process. The script below has a section for an if/else statement to create an output that is tailored to your desired results. This if/else statement needs to be written based on your organization’s business logic. The script defaults the dynamic process property executionMode to “TEST_MODE”, but the if/else statement will need to be used to correctly set the executionMode DPP.

import java.util.Properties;
import java.io.InputStream;
import com.boomi.execution.ExecutionManager;
import com.boomi.execution.ExecutionTask;
import com.boomi.execution.ExecutionUtil;

ExecutionTask execTaskCurrent = ExecutionManager.getCurrent();
logger = ExecutionUtil.getBaseLogger();

// If running in Test mode: TEST
// If running deployed: NORMAL
String getExecutionMode =execTaskCurrent.getExecutionMode()

// If user executed: USER
// If executed by a schedule: SCHEDULE
// If executed by a listener: LISTENER
String getSource = execTaskCurrent.getSource();

// If initial run: NONE
// If rerun: START (this applies if you are rerunning docs in test more, a manual retry, or a schedule retry)
String getRerunMode = execTaskCurrent.getRerunMode();

logger.info("getExecutionMode: " + getExecutionMode);
logger.info("getSource: " + getSource);
logger.info("getRerunMode: " + getRerunMode);

// Add some if/else logic to set a standard output list and set the dynamic
// process property executionMode
String executionMode = "TEST_MODE"

ExecutionUtil.setDynamicProcessProperty("executionMode",executionMode,false);

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
    InputStream is = dataContext.getStream(i);
    Properties props = dataContext.getProperties(i);
    dataContext.storeStream(is, props);
}

Article originally posted at Boomi Community.

Published Jun 5, 2021

Developing a better world.© All rights reserved.