# Script Contexts

There are two different script context types:

* [Process Script Context](#processscriptcontext)
* [Map Script Context](#mapscriptcontext)

Both are based on [ScriptContext](#scriptcontext) and this is what they both have in common.

## ProcessScriptContext

The `ProcessScriptContext` contains the **input and output documents**, in addition to the information in `ScriptContext`. A Document consists of the document content and its (dynamic document) properties.

```groovy
public List<Document> inputDocuments = []
public List<Document> outputDocuments = []
```

<details>

<summary>Process ScriptContext example</summary>

The following examples demonstrates how to setup all kind of properties and documents to run a process script.

```groovy
ProcessScriptContext context = new ProcessScriptContext()
// Initialize 
// * Execution context          : executionContexts
// * Dynamic Process Properties : dynProcPros
// * Process Properties         : procPros
// * Documents                  : inputDocuments
//      incl. Dynamic Document Properties
// --------------------------------------------------------------

// context.executionProperties.ACCOUNT_ID = "My Account ID"

context.dynProcPros.DPP_ProcPropString = "My Process Property"
context.dynProcPros.DPP_IntValue = 0

// region Process Property 

final String PROCESS_PROPERTY_COMPONENT_ID = "8fb41f63-a988-4778-8cc8-0144f30ace81"
final String VAL1_ID = "eea9e988-cb14-4a84-ba37-ee455451a741"
final String VAL2_ID = "2c68fb60-8431-46cc-9da9-cbe10d446a0e"

// Wrap key in parenthesis so that the variables (Ids) are taken
// and not the text as a string

def procPropValue1 = 4711
def procPropValue2 = "Markus Schmidt"

context.procPros = [ (PROCESS_PROPERTY_COMPONENT_ID): 
	[
		(VAL1_ID): procPropValue1,
		(VAL2_ID): procPropValue2
	]]
// endregion

// region Documents

final String DDP_Name = "DDP_IntValue"
int[] ddpValues = [ 10, 11, 12]

context.inputDocuments = 
[
	Document.fromText('''
	{
		"firstname" : "Walter",
		"lastname" : "Schmidt"
	}''', [(DDP_Name): ddpValues[0]]),
	Document.fromFile( _testFiles.get( "demoDoc01.json") , [(DDP_Name): ddpValues[1]]),
	Document.fromFile( _testFiles.get( "demoDoc02.json") , [(DDP_Name): ddpValues[2]])
]

// endregion

_testScript.run(context)
```

</details>

## MapScriptContext

A `MapScriptContext` represents the input and output variables as they are defined on the platform, in addition to the information in `ScriptContext`.

<figure><img src="/files/eUPk9tua4QGKSj7uOXCw" alt=""><figcaption></figcaption></figure>

```groovy
MapScriptContext scriptContext = new MapScriptContext(  [
    a: 5,
    b: 7
])

_testScript.run(scriptContext)

assert scriptContext.variables.total 
  == (scriptContext.variables.a as int) 
   + (scriptContext.variables.b as int), 
   "Calculation result does not meet expectations!"
```

## ScriptContext

The `ScriptContext` is the base class,`MapScriptContext` and `ProcessScriptContext` inherit from it. The ScriptContext hosts:

* Process Properties - procProps
* Dynamic Process Properties - dynProcProps
* Execution Properties - executionProperties

```groovy
public Map dynProcPros = [:]
public Map procPros = [:]

public final Map executionProperties =
[
 ACCOUNT_ID  : 'IntelliJ_IDEA-M42S66',
 ATOM_ID     : '0b6e3ab7-9d81-4954-b781-d212195e577c',
 ATOM_NAME     : 'Markus Groovy 4 Boomi',

 // null on local Atom, some text on Cloud ATOM (e.g. NODE_ID = atom01)
 NODE_ID       : null,

 // set before script starts - ProcessScriptContext run
 DOCUMENT_COUNT: 0,
 
 // see Process Call Chain
 // If you do not plan to use ExecutionTask objects in your 
 // scripts you can live with the defaults and you won't care!
 EXECUTION_ID : generateExecutionId(), // random
 PROCESS_ID   : UUID.randomUUID().toString(),
 PROCESS_NAME : "My Main Process"
]
```

{% hint style="info" %}
If you want to use `ExecutionTask` objects in your scripts,\
read also about [The Process Call Chain](/boomi-scriptease/test-contexts/the-process-call-chain.md)
{% endhint %}


---

# 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/knowlede-base/script-contexts.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.
