> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m3ter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# General Functions

## Abort Workflow

**Function name:** `AbortWorkflowFunction`
**Category:** Logic
**Destination:** General

Terminates the workflow with an error message

### Parameters

| Name      | Label   | Required | Description   |
| --------- | ------- | :------: | ------------- |
| `message` | Message |    No    | Error message |

### Exits

| Exit        | Description |
| ----------- | ----------- |
| `TERMINATE` | -           |

## Add to List

**Function name:** `AddToListFunction`
**Category:** Variables
**Destination:** General

Add a variable to a list

### Parameters

| Name       | Label | Required | Description                                                    |
| ---------- | ----- | :------: | -------------------------------------------------------------- |
| `listName` | Name  |    Yes   | The name by which this list can be referred to in the workflow |
| `path`     | Path  |    Yes   | The path to the state variable to add to the list              |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Apply Transformation

**Function name:** `ApplyTransformationFunction`
**Category:** Convert
**Destination:** General

Perform a pre-defined transformation

### Parameters

| Name                          | Label          | Required | Description                                                                              |
| ----------------------------- | -------------- | :------: | ---------------------------------------------------------------------------------------- |
| `sourceName`                  | Source         |    Yes   | Name of variable by which name of the object to transform should be retrieved from state |
| `integrationTransformationId` | Transformation |    Yes   | The UUID of the transformation to apply                                                  |
| `stateVariable`               | Destination    |    Yes   | Name of the variable by which the transformed object will be stored in state             |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## If

**Function name:** `CalculationFunction`
**Category:** Logic
**Destination:** General

Evaluate a calculation and choose a path based one whether it's true or false

### Parameters

| Name          | Label       | Required | Description                 |
| ------------- | ----------- | :------: | --------------------------- |
| `calculation` | Calculation |    Yes   | the calculation to evaluate |

### Exits

| Exit    | Description |
| ------- | ----------- |
| `TRUE`  | -           |
| `FALSE` | -           |

## Chunk Iterator

**Function name:** `ChunkIteratorFunction`
**Category:** Logic
**Destination:** General

Wraps a list or iterator and yields it in chunks of up to N elements.

### Parameters

| Name            | Label      | Required | Description                                                   |
| --------------- | ---------- | :------: | ------------------------------------------------------------- |
| `source`        | Source     |    Yes   | State path to a list, or the name of an iterator, to chunk.   |
| `chunkSize`     | Chunk size |    No    | Maximum number of elements per chunk.                         |
| `stateVariable` | State name |    Yes   | The name to expose the chunk iterator under (loop over this). |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Clear Error Status

**Function name:** `ClearErrorStatusFunction`
**Category:** Logic
**Destination:** General

Clears the last error from the state, allowing the workflow to complete successfully. Place this on an error branch once the error has been handled.

### Parameters

| Name | Label | Required | Description |
| ---- | ----- | :------: | ----------- |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Convert line items

**Function name:** `ConvertLineItemsFunction`
**Category:** Convert
**Destination:** General

Convert line items

### Parameters

| Name            | Label       | Required | Description                                                                                                  |
| --------------- | ----------- | :------: | ------------------------------------------------------------------------------------------------------------ |
| `stateVariable` | Destination |    Yes   | The variable name to store the results of the conversion in the IntegrationState (e.g. `convertedLineItems`) |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Create Index

**Function name:** `CreateIndexFunction`
**Category:** Write
**Destination:** General

Create a index on a table in m3sh DB

### Parameters

| Name              | Label             | Required | Description               |
| ----------------- | ----------------- | :------: | ------------------------- |
| `tableName`       | Table Name        |    Yes   | Table name of the table   |
| `indexName`       | Index Name        |    Yes   | The name of the index     |
| `fieldsToIndex`   | Fields to index   |    Yes   | The fields to be indexed  |
| `fieldsToInclude` | Fields to include |    No    | The fields to be included |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Create List

**Function name:** `CreateStateListFunction`
**Category:** Variables
**Destination:** General

Create a list which can then be added to

### Parameters

| Name       | Label | Required | Description                                                      |
| ---------- | ----- | :------: | ---------------------------------------------------------------- |
| `listName` | Name  |    Yes   | The name by which this list can be referred to in the workflow   |
| `listType` | Type  |    No    | The type of object to be added to the list (defaults to objects) |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Create Map

**Function name:** `CreateStateMapFunction`
**Category:** Variables
**Destination:** General

Create a map which can then be added to

### Parameters

| Name      | Label | Required | Description                                                   |
| --------- | ----- | :------: | ------------------------------------------------------------- |
| `mapName` | Name  |    Yes   | The name by which this map can be referred to in the workflow |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Create Table

**Function name:** `CreateTableFunction`
**Category:** Write
**Destination:** General

Create a table in m3sh DB and populates it with data from an iterator.

### Parameters

| Name        | Label      | Required | Description             |
| ----------- | ---------- | :------: | ----------------------- |
| `tableName` | Table Name |    Yes   | Table name of the table |
| `source`    | Source     |    Yes   | The source of the data  |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## For Loop

**Function name:** `ForLoopFunction`
**Category:** Logic
**Destination:** General

Increment or decrement a counter between two numbers.

### Parameters

| Name                  | Label                   | Required | Description                         |
| --------------------- | ----------------------- | :------: | ----------------------------------- |
| `startValue`          | Start value (inclusive) |    Yes   | The value to start the for loop at. |
| `endValue`            | End value (exclusive)   |    Yes   | The value to end the for loop at.   |
| `counterVariableName` | Counter variable        |    Yes   | Counter variable name.              |
| `decrement`           | Decrement               |    No    | Decrement the counter               |

### Exits

| Exit    | Description |
| ------- | ----------- |
| `NEXT`  | -           |
| `ERROR` | -           |

## Get First Result Or Null

**Function name:** `GetFirstResultOrNullFunction`
**Category:** Variables
**Destination:** General

Retrieves the first element from a list or iterator and stores it in a state variable.

### Parameters

| Name                  | Label           | Required | Description                                                                        |
| --------------------- | --------------- | :------: | ---------------------------------------------------------------------------------- |
| `sourceObjectPath`    | Source          |    Yes   | The list or iterator to retrieve the first element from.                           |
| `outputStateVariable` | Output variable |    Yes   | The name of the state variable in which to store the first element (null if none). |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Has Results

**Function name:** `HasResultsFunction`
**Category:** Logic
**Destination:** General

Inspect a list or iterator and branch based on whether it contains values or not

### Parameters

| Name               | Label  | Required | Description                         |
| ------------------ | ------ | :------: | ----------------------------------- |
| `sourceObjectPath` | Source |    Yes   | Source of the objects to loop over. |

### Exits

| Exit    | Description |
| ------- | ----------- |
| `TRUE`  | -           |
| `FALSE` | -           |

## Loop

**Function name:** `LoopFunction`
**Category:** Logic
**Destination:** General

Loop over a collection of objects and apply functions to them

### Parameters

| Name                  | Label            | Required | Description                         |
| --------------------- | ---------------- | :------: | ----------------------------------- |
| `sourceObjectPath`    | Source           |    Yes   | Source of the objects to loop over. |
| `counterVariableName` | Counter variable |    Yes   | Counter variable name.              |
| `elementVariableName` | Element variable |    No    | Element variable name.              |

### Exits

| Exit    | Description |
| ------- | ----------- |
| `NEXT`  | -           |
| `ERROR` | -           |

## List Map Values

**Function name:** `MapValuesFunction`
**Category:** Variables
**Destination:** General

Creates a list of values stored in a map

### Parameters

| Name        | Label      | Required | Description                                                                                                   |
| ----------- | ---------- | :------: | ------------------------------------------------------------------------------------------------------------- |
| `mapPath`   | Map Path   |    Yes   | The state path of the map to retrieve values from                                                             |
| `listPath`  | List Path  |    Yes   | The state path of the list that will be created containing values copied from the map                         |
| `fieldName` | Field Name |    No    | The field within each map value that will be listed - if this is not set, the map value itself will be listed |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Merge Lists

**Function name:** `MergeListsFunction`
**Category:** Variables
**Destination:** General

Merges two list of object with a matching field value. The merged objects are added to the destination list

### Parameters

| Name                       | Label             | Required | Description                                                             |
| -------------------------- | ----------------- | :------: | ----------------------------------------------------------------------- |
| `leftList`                 | Left List         |    Yes   | The left hand source list.                                              |
| `rightList`                | Right List        |    Yes   | The right hand source list.                                             |
| `mergedListsStateVariable` | Merged lists name |    Yes   | The variable name in which the merged list will be stored in the state. |
| `field`                    | Field             |    Yes   | The field name that the lists will be joined on.                        |
| `joinType`                 | Join Type         |    Yes   | The way in which the lists are joined.                                  |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Merge Objects

**Function name:** `MergeObjectsFunction`
**Category:** Convert
**Destination:** General

Merge the source object into the destination object.

### Parameters

| Name               | Label                | Required | Description                                                                                                       |
| ------------------ | -------------------- | :------: | ----------------------------------------------------------------------------------------------------------------- |
| `sourceObjectName` | Source Name          |    Yes   | The name of the object                                                                                            |
| `targetObjectName` | Object to merge into |    Yes   | The name of the object to merge with. Fields in this object that are not also in the source will remain unchanged |
| `fieldName`        | Field name           |    No    | Optional field name to use when merging                                                                           |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Merge Transformation

**Function name:** `MergeTransformationFunction`
**Category:** Convert
**Destination:** General

Coalesces two objects using a transformation. Values in the mergeObject are overwritten by transformed fields from the sourceObject; otherwise they remain unchanged.

### Parameters

| Name                          | Label            | Required | Description                                                                                                                |
| ----------------------------- | ---------------- | :------: | -------------------------------------------------------------------------------------------------------------------------- |
| `integrationTransformationId` | Transformation   |    Yes   | The UUID of the transformation to apply                                                                                    |
| `sourceObjectName`            | Source Name      |    Yes   | The name of the object to transform                                                                                        |
| `mergeObjectName`             | Object to Merge  |    Yes   | The name of the object to merge with. Fields in this object that are not transformed from the source will remain unchanged |
| `stateVariable`               | Destination Name |    Yes   | The name of the object to create in the state                                                                              |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Remove Field

**Function name:** `RemoveFieldFunction`
**Category:** Convert
**Destination:** General

Removes a field on an object within the state.

### Parameters

| Name        | Label      | Required | Description                                                                                            |
| ----------- | ---------- | :------: | ------------------------------------------------------------------------------------------------------ |
| `statePath` | State Path |    Yes   | Path to the field within the state to remove. If the field is an object, the entire object is removed. |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Run error workflow

**Function name:** `RunErrorWorkflowFunction`
**Category:** Logic
**Destination:** General

Run workflow to handle an error. No further functions will be run in this workflow.

### Parameters

| Name                       | Label                      | Required | Description                                                                         |
| -------------------------- | -------------------------- | :------: | ----------------------------------------------------------------------------------- |
| `integrationDestinationId` | Integration destination ID |    Yes   | Workflow's Integration destination ID                                               |
| `failWorkflow`             | Fail workflow              |    No    | If enabled, this (current) workflow will fail once the error workflow is completed. |
| `messageLookup`            | Message                    |    No    | Error message to be used.                                                           |

### Exits

| Exit | Description |
| ---- | ----------- |

## Run workflow

**Function name:** `RunWorkflowFunction`
**Category:** Logic
**Destination:** General

Run a workflow

### Parameters

| Name                       | Label                      | Required | Description                           |
| -------------------------- | -------------------------- | :------: | ------------------------------------- |
| `integrationDestinationId` | Integration destination ID |    Yes   | Workflow's Integration destination ID |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Set Field

**Function name:** `SetFieldFunction`
**Category:** Convert
**Destination:** General

Update a field on an object within the state.

### Parameters

| Name        | Label      | Required | Description                                                                                  |
| ----------- | ---------- | :------: | -------------------------------------------------------------------------------------------- |
| `statePath` | State Path |    Yes   | Path to the field within the state to update. If the field does not exist it will be created |
| `lookup`    | Lookup     |    Yes   | The value to set the field to.                                                               |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Set Multiple Fields

**Function name:** `SetMultiFieldsFunction`
**Category:** Convert
**Destination:** General

Update one or more fields on an object within the state.

### Parameters

| Name        | Label      | Required | Description                                    |
| ----------- | ---------- | :------: | ---------------------------------------------- |
| `statePath` | State Path |    Yes   | Path to the object within the state to update. |
| `lookups`   | Lookup     |    Yes   | The value to set the field to.                 |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Create SFTP file

**Function name:** `SftpDataOutputFunction`
**Category:** Write
**Destination:** General

Create a file on a SFTP server which can be used for writing data to.

### Parameters

| Name                       | Label            | Required | Description                                                                                              |
| -------------------------- | ---------------- | :------: | -------------------------------------------------------------------------------------------------------- |
| `integrationCredentialsId` | Credentials      |    Yes   | The basic credentials required to connect to the SFTP server.                                            |
| `host`                     | Host             |    Yes   | Host name of the server to connect to.                                                                   |
| `port`                     | Port             |    No    | The port on which to connect to the SFTP server on. If unspecified, the default value of 22 will be used |
| `remoteFileName`           | Destination File |    Yes   | The remote file to write to.                                                                             |
| `stateVariable`            | State variable   |    Yes   | The variable name by which this output can be referenced using                                           |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Sort List

**Function name:** `SortListFunction`
**Category:** Variables
**Destination:** General

Sort an existing list in the state based on a field.

### Parameters

| Name         | Label      | Required | Description                                                      |
| ------------ | ---------- | :------: | ---------------------------------------------------------------- |
| `listName`   | Name       |    Yes   | The name of the list in the state to sort.                       |
| `sortField`  | Sort Field |    Yes   | The name of the field to sort on.                                |
| `descending` | Descending |    No    | Sort the list in a descending order. e.g. (3, 2, 1) or (Z, Y, X) |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## SQL Select Data

**Function name:** `SqlSelectFunction`
**Category:** Read
**Destination:** General

Run SQL against a table

### Parameters

| Name           | Label         | Required | Description                                                        |
| -------------- | ------------- | :------: | ------------------------------------------------------------------ |
| `sql`          | SQL           |    Yes   | Select statement. N.B. Datastore does not support all SQL keywords |
| `responsePath` | Response Path |    Yes   | The path in which to store the response in the state.              |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Validate

**Function name:** `ValidateFunction`
**Category:** Logic
**Destination:** General

Validates an object from the state against a schema (if supported) and branches based on whether it is valid or not.

### Parameters

| Name         | Label       | Required | Description                                  |
| ------------ | ----------- | :------: | -------------------------------------------- |
| `system`     | System      |    Yes   | The system to validate against.              |
| `schemaName` | Schema name |    Yes   | The name of the schema to validate against.  |
| `objectName` | Object      |    Yes   | The name of the object in state to validate. |

### Exits

| Exit      | Description |
| --------- | ----------- |
| `VALID`   | -           |
| `INVALID` | -           |

## Write CSV

**Function name:** `WriteObjectToCsvFunction`
**Category:** Write
**Destination:** General

Writes data to a declared output as a CSV row.

### Parameters

| Name     | Label  | Required | Description                           |
| -------- | ------ | :------: | ------------------------------------- |
| `output` | Output |    Yes   | Name of a previously declared output. |
| `source` | Source |    Yes   | Source state object to write          |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |

## Write JSON

**Function name:** `WriteObjectToJsonFunction`
**Category:** Write
**Destination:** General

Writes data to a declared output as a JSON object. Multiple objects written to the same format are separated by a line break (JSONL)

### Parameters

| Name     | Label  | Required | Description                           |
| -------- | ------ | :------: | ------------------------------------- |
| `output` | Output |    Yes   | Name of a previously declared output. |
| `source` | Source |    Yes   | Source state object to write          |

### Exits

| Exit   | Description |
| ------ | ----------- |
| `NEXT` | -           |
