# Workflow Services

## Overview

Workflows are a series of steps that moves a process from one state to another state by actions performed by different kind of Actors - Humans, Machines, Time based events etc. to achieve a goal like onboarding an employee, or approve an application or grant a resource etc. The *egov-workflow-v2* is a workflow engine which helps in performing these operations seamlessly using a predefined configuration.

## Pre-requisites

Before you proceed with the documentation, make sure the following pre-requisites are met -

* Java 8
* Kafka server is up and running
* egov-persister service is running and has workflow persister config path added in it
* PSQL server is running and a database is created to store workflow configuration and data

## Key Functionalities

* Always allow anyone with a role in the workflow state machine to view the workflow instances and comment on it
* On the creation of workflow, it will appear in the inbox of all employees that have roles that can perform any state transitioning actions in this state.
* Once an instance is marked to an individual employee it will appear only in that employee's inbox although point 1 will still hold true and all others participating in the workflow can still search it and act if they have necessary action available to them
* If the instance is marked to a person who cannot perform any state transitioning action, they can still comment/upload and mark to anyone else.
* **Overall SLA:** SLA for the complete processing of the application/Entity
* **State-level SLA:** SLA for a particular state in the workflow

|                            |                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Environment Variables**  | **Description**                                                                                                                                                                                                                                                                                                                                      |
| egov.wf.default.offset     | The default value of offset in search                                                                                                                                                                                                                                                                                                                |
| egov.wf.default.limit      | The default value of limit in search                                                                                                                                                                                                                                                                                                                 |
| egov.wf.max.limit          | The maximum number of records that are returned in search response                                                                                                                                                                                                                                                                                   |
| egov.wf.inbox.assignedonly | Boolean flag if set to *true* default search will return records assigned to the user only, if *false* it will return all the records based on the user’s role. *(default search is the search call when no query params are sent and based on the RequestInfo of the call, records are returned, it’s used to show applications in employee inbox)* |
| egov.wf.statelevel         | Boolean flag set to *true* if a state-level workflow is required                                                                                                                                                                                                                                                                                     |

#### Interaction Diagram

<div align="left"><img src="/files/-MHHNq7GecqWUTHvjhzZ" alt=""></div>

## Deployment Details

1. Deploy the latest version of egov-workflow-v2 service
2. Add businessService persister yaml path in persister configuration
3. Add Role-Action mapping for BusinessService APIs
4. Overwrite the egov.wf.statelevel flag ( *true* for state level and *false* for tenant level)
5. Create businessService (workflow configuration) according to product requirements
6. Add Role-Action mapping for */processInstance/\_search* API
7. Add workflow persister yaml path in persister configuration

## Configuration Details

For Configuration details please refer to the links in Reference Docs

## Integration Details

### Integration Scope

The workflow configuration can be used by any module which performs a sequence of operations on an application/Entity. It can be used to simulate and track processes in organisations to make it more efficient too and increase accountability.

### Integration Benefits

* Role-based workflow
* An easy way of writing rule
* File movement within workflow roles

### Steps to Integration

1. To integrate, host of egov-workflow-v2 should be overwritten in helm chart
2. /process/\_search should be added as the search endpoint for searching workflow process Instance object.
3. /process/\_transition should be added to perform an action on an application. *(It’s for internal use in modules and should not be added in Role-Action mapping)*
4. The workflow configuration can be fetched by calling *\_search* API to check if data can be updated or not in the current state

## Reference Docs

### Doc Links

| Title                                        | Link                                                                                                                                                                                   |
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Configuring Workflows For New Product/Entity | [Configuring Workflows For New Product/Entity](/local-governance/v2.7/platform/configure-digit/configuring-digit-services/configuring-workflows/configuring-workflow-for-an-entity.md) |
| Setting Up Workflows                         | [Setting Up Workflows](/local-governance/v2.7/platform/configure-digit/configuring-digit-services/configuring-workflows/setting-up-workflow.md)                                        |
| API Swagger Documentation                    | [Swagger Documentation](https://raw.githubusercontent.com/egovernments/core-services/master/docs/worfklow-2.0)                                                                         |
| Migration to Workflow 2.0                    | [Workflow 2.0 Configuration doc](https://digit-discuss.atlassian.net/wiki/spaces/EPE/pages/120619031/Workflow+2.0+Configuration+doc)                                                   |

### API List

| Title                       | Link                                                          |
| --------------------------- | ------------------------------------------------------------- |
| */businessservice/\_create* | <https://www.getpostman.com/collections/8552e3de40c819e34190> |
| */businessservice/\_update* | <https://www.getpostman.com/collections/8552e3de40c819e34190> |
| */businessservice/\_search* | <https://www.getpostman.com/collections/8552e3de40c819e34190> |
| */process/\_transition*     | <https://www.getpostman.com/collections/8552e3de40c819e34190> |
| */process/\_search*         | <https://www.getpostman.com/collections/8552e3de40c819e34190> |

*(Note: All the APIs are in the same postman collection, therefore, the same link is added in each row)*

[![Creative Commons License](https://i.creativecommons.org/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)All content on this page by [eGov Foundation ](https://egov.org.in/)is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).


---

# 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://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/workflow-services.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.
