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

# Create Process

## Simplest example

Simple create process query.
This one is likely never going to be used, because 99% of the time, we are manipulating data into a database (entity). But is possible to do it on a process as well.

```json Simple request theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "name",
          "type": "TEXT"
        },
        {
          "label": "age",
          "type": "NUMBER"
        }
      ]
    }
  ]
}
```

## Updating data on a Database (Entity)

Simplest request for referencing an entity.

In this scenario, someone from the HR deparment has the permission to add a new user, and the HR Manager has to approve that new user before it gets added to the Users database

```json Simple request with entity_update theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["WRITE"]
        }
      ]
    }
  ]
}
```

## Entity connection example.

In this example, as the two steps on the process manipulate the same entity, the default logic is to connect these two steps into the same line being manipulated.

This means that when the second step comes around, it will edit columns D and E for the line step 1 created on the Users database.

If none of these variables are sent, all columns will be shown

```json Simple request with autoFillEntityRelation theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["WRITE"],
          "showColumns": ["Name", "Surname", "Birthdate"]
        }
      ]
    }
    {
      "label": "Step 2",
      "policyNames": ["HR Director"],
      "parameters": [
        {
          "label": "Update User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["EDIT"],
          "showColumns": ["Role", "Experience"]
        }
      ],
      "stepIdsDependencies": ["Step 1"]
    },
  ]
}
```

## VIEW Entity Operation Example

If you want to view some data on the Entity, use the "VIEW" entityOperation.

In this example, user is viewing all data from the Users entity, but only for columns "Name", "Surname" and "Birthdate"

He also has another entity update param on the same step that allows him to EDIT columns "Role" and "Experience" of any user.

```json Simple request with autoFillEntityRelation theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["VIEW"],
          "showColumns": ["Name", "Surname", "Birthdate"]
        }
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["EDIT"],
          "showColumns": ["Role", "Experience"]
        }
      ]
    }
  ]
}
```

This Behaviour is automatically defined when you update the same entity in different steps.

So, for the following request, Step 2 will already have the VIEW parameter created, with showColumns "Name", "Surname" and "Birthdate" already set

```json Simple request with autoFillEntityRelation theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["WRITE"],
          "showColumns": ["Name", "Surname", "Birthdate"]
        }
      ]
    }
    {
      "label": "Step 2",
      "policyNames": ["HR Director"],
      "parameters": [
        {
          "label": "Update User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["EDIT"],
          "showColumns": ["Role", "Experience"]
        }
      ],
      "stepIdsDependencies": ["Step 1"]
    },
  ]
}
```

## showColumns and hideColumns Example.

If a database is too big, you might want to hide or select some columns to be manipulated in each step.

You can either set variable `showColumns` or `hideColumns` which is an array of strings - each string being the columns of the entity you are manipulating.

If both `showColumns` and `hideColumns` are sent, only the `hideColumns` variable will be considered.

```json Simple request with autoFillEntityRelation theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["WRITE"],
          "showColumns": ["Name", "Surname", "Birthdate"]
        }
      ]
    }
    {
      "label": "Step 2",
      "policyNames": ["HR Director"],
      "parameters": [
        {
          "label": "Update User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["EDIT"],
          "showColumns": ["Role", "Experience"]
        }
      ],
      "stepIdsDependencies": ["Step 1"]
    },
  ]
}
```

## Advanced Entity connection example.

In this example, as the first two steps create new lines on the Users database, you might want to connect to one or the other on the third step.

To define which step you would like step 3 to be connected to, simpliy send the `autoFillEntityRelation` variable with the step name you would like to connect to.

```json Advanced request with multiple entity manipulations theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["HR Deparment", "HR Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Project",
          "entityOperation": ["WRITE"],
          "showColumns": ["A", "B", "C"]
        },
      ]
    }
    {
      "label": "Step 2",
      "policyNames": ["Sources Deparment", "Sources Manager"],
      "parameters": [
        {
          "label": "Create Quote",
          "type": "ENTITY_UPDATE",
          "entityId": "Project", // automatically connects to the line created on step 1. Because it has step 1 as a dependency. Would've also worked if variable was not set
          "entityOperation": ["WRITE"],
          "showColumns": ["D", "E"],
        }
      ],
      "stepIdsDependencies": ["Step 1"]
    },
    {
      "label": "Step 3",
      "parameters": [
        {
          "policyNames": ["HR Director"],
          "label": "Update User",
          "type": "ENTITY_UPDATE",
          "entityId": "Project",
          "entityOperation": ["EDIT"],
          "autoFillEntityRelation": "Step2" // connects to the line created on step 2. Would've also worked if variable was not set
          "showColumns": ["F", "G"]
        },
      ],
      "stepIdsDependencies": ["Step 2"]
    },
  ]
}
```

### Required Variables for Step Deadlines

To define a deadline for the step, you need to send the following variables:

| Variable          | Type   | Description                                                                       |
| ----------------- | ------ | --------------------------------------------------------------------------------- |
| `legalContractId` | string | ID of the legal contract                                                          |
| `frequency`       | enum   | Recurrence pattern: `'weekly'`, `'monthly'`, or `'yearly'`                        |
| `frequencyDate`   | number | Date specification based on frequency (see table below)                           |
| `deadline`        | number | Deadline duration in the unit specified by `deadlineType`                         |
| `deadlineType`    | enum   | Time unit for deadline: `'days'`, `'weeks'`, or `'months'` (defaults to `'days'`) |

#### Frequency Date Values

The `frequencyDate` parameter varies based on the selected `frequency`:

| Frequency   | Valid Values | Description                                    |
| ----------- | ------------ | ---------------------------------------------- |
| `'weekly'`  | 1-7          | Day of the week (1 = Sunday, 7 = Saturday)     |
| `'monthly'` | 1-31         | Day of the month                               |
| `'yearly'`  | 1-12         | Month of the year (1 = January, 12 = December) |

In this example, the Manager has 2 days to validate the work of the manager. And this is a process that repeats every week.

```json Define step deadline theme={null}
{
  "name": "Process A",
  "steps": [
    {
      "label": "Step 1",
      "policyNames": ["Trainee", "Manager"],
      "parameters": [
        {
          "label": "Create New User",
          "type": "ENTITY_UPDATE",
          "entityId": "Users",
          "entityOperation": ["WRITE"],
          "showColumns": ["Name", "Surname", "Birthdate"],
          "legalContractId": "uuid",
          "frequency": "weekly",
          "deadline": "2"
        }
      ]
    }
  ]
}
```
