# The Process Call Chain

{% hint style="warning" %}
If you do **not** use **`ExecutionTask`** you can live with the defaults - as I have done for four years. Skip this page!
{% endhint %}

Recently I came accross a script that used the following code with `ExecutionTask` :

```groovy
ExecutionTask currentProcessExecution = ExecutionManager.getCurrent()
_logger.info( "*** Script hosting process name  : " +  currentProcessExecution.getProcessName())

ExecutionTask t = currentProcessExecution
while( t.getParent() != null) t = t.getParent()

_logger.info( "*** Top-Process Name : " +  t.getProcessName())

// *** Script hosting process name  : subPr.subProcess_01_01
// *** Top-Process Name             : Custom Main Process
```

## The Basics

A script is hosted in a process. This process can be a sub-process of another process(es).

For example:

* **Main** Process calls (Level -2)
  * **subProcess01** routes to (Level -1)
    * **subPr.subProcess\_01\_01**, where the script runs on! (Level 0)

{% hint style="info" %}
The [ExecutionProperties](/boomi-scriptease/knowlede-base/script-contexts.md#scriptcontext) `EXECUTION_ID, PROCESS_ID, PROCESS_NAME`\
refer to the script's (hosting) process.
{% endhint %}

What you need to undestand is, that each process *execution* has its own `ExecutionTask` object with different properties, and you can traverse up the hierarchy using the `getParent()` method.

```groovy
bool isTopLevelProcess = executionTask.getParent() == null
```

#### Process Name = subPr.subProcess\_01\_01

```groovy
ExecutionTask currentProcessExecution = ExecutionManager.getCurrent()
```

```
+ ExecutionTask Properties - Level=0
- Is Top-Level           = false
- Id                     = execution-59f72f67-95ed-4917-8c54-8d3a3c5f2b02-2024.06.26
- Execution Id           = execution-59f72f67-95ed-4917-8c54-8d3a3c5f2b02-2024.06.26
- Process   Name         = subPr.subProcess_01_01
- Process   Id           = 6a3bfa82-997a-4842-8b6b-1362e07016dc
- Component Id           = 6a3bfa82-997a-4842-8b6b-1362e07016dc
- Start Time             = 1719397726865
```

#### Process Name = subProcess01

```groovy
ExecutionTask level1 = currentProcessExecution.getParent()
```

```
+ ExecutionTask Properties - Level=1 - bottom (=0) up to top-level
- Is Top-Level           = false
- Id                     = execution-d41b8cd6-0c92-4edd-9452-77ac20499071-2024.06.26
- Execution Id           = execution-d41b8cd6-0c92-4edd-9452-77ac20499071-2024.06.26
- Process   Name         = subProcess01
- Process   Id           = 2b626af5-4bec-422b-a9ec-a6d0a15090e8
- Component Id           = 2b626af5-4bec-422b-a9ec-a6d0a15090e8
- Start Time             = 1719397726637
```

#### Process Name = Main

```groovy
ExecutionTask level0 = currentProcessExecution.getParent()
```

```
+ ExecutionTask Properties - Level=0 - bottom (=0) up to top-level
- Is Top-Level           = false
- Id                     = execution-59f72f67-95ed-4917-8c54-8d3a3c5f2b02-2024.06.26
- Execution Id           = execution-59f72f67-95ed-4917-8c54-8d3a3c5f2b02-2024.06.26
- Process   Name         = Custom Main Process
- Process   Id           = 6a3bfa82-997a-4842-8b6b-1362e07016dc
- Component Id           = 6a3bfa82-997a-4842-8b6b-1362e07016dc
- Start Time             = 1719397726865
```

### How to define a process call hierarchy in a Test

<mark style="color:blue;">**`import msPro.scriptease.*`**</mark> <mark style="color:red;">`// Important`</mark>

```groovy
ProcessScriptContext context = new ProcessScriptContext(
inputDocuments: [ ...],

// Override to test process chains 
processCallChain : [
		new ProcessExecutionProperties( "Custom Main Process"),
		new ProcessExecutionProperties( "subProcess01"),
		new ProcessExecutionProperties( "subPr.subProcess_01_01")
])
```

`Process Id` (=`Component Id`) are set to a randowm Guid by default. This can be overridden in the `ProcessExecutionProperties` constructor.

`StartTime` and `executionId` are set a atuomatically.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boomi.markusschmidt.pro/boomi-scriptease/test-contexts/the-process-call-chain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
