Run a business process using base request handler
@creatio-devkit/common
lets you run business processes using base request handler. This ensures context transfer, enabling stable and predictable business logic execution as part of automation and development. Learn more: Base request handlers.
Creatio forbids running the business process that has output parameters in the background.
To run a business process:
-
Add a button to run a business process from a Freedom UI page if needed. Instructions: Set up Button components (user documentation).
-
Add the dependencies. Instructions: Display the value of a system variable (similarly to step 2). Instead of the
SysValuesService
service, use theProcessEngineService
service that lets you interact with business processes. -
Set up how to handle the action executed on button click.
- Go to the
viewConfigDiff
schema section → select required element. For example,SomeButton
. - Bind the sending of base
crt.RunBusinessProcessRequest
request to the element event. We recommend using the basecrt.RunBusinessProcessRequest
request that has parameters to determine the context to run the business process precisely, based on your business goals. Learn more: Base request handlers.
View the example that binds the sending of base
crt.RunBusinessProcessRequest
request to the element event below. The type of business process to run, i. e., theprocessRunType
parameter value, determines the entity with which the business process interacts. Learn more: Base request handlers.- viewConfigDiff schema section (for the selected app page)
- viewConfigDiff schema section (without connection to a dedicated app page)
- viewConfigDiff schema section (for the selected list records)
viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
/* Button that calls the business process. */
{
"operation": "insert",
"name": "SomeButton",
"values": {
...,
"clicked": {
/* Bind the sending of the base request to the "clicked" button event. */
"request": "crt.RunBusinessProcessRequest",
/* List of request parameters. */
"params": {
/* Code of the business process schema. */
"processName": "CodeOfSomeBusinessProcessSchema",
/* Type of business process to run. Run the business process for the selected app page. */
"processRunType": "ForTheSelectedPage",
/* Save the current record before the business process is run. */
"saveAtProcessStart": true,
/* Display the notification when the business process is run. */
"showNotification": true,
/* Name of the process parameter that is received by the record whose ID is specified. */
"recordIdProcessParameterName": "SomeBusinessProcessParameter"
}
}
},
...
},
...
]/**SCHEMA_VIEW_CONFIG_DIFF*/,viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
/* Button that calls the business process. */
{
"operation": "insert",
"name": "SomeButton",
"values": {
...,
"clicked": {
/* Bind the sending of the base request to the "clicked" button event. */
"request": "crt.RunBusinessProcessRequest",
/* List of request parameters. */
"params": {
/* Code of the business process schema. */
"processName": "CodeOfSomeBusinessProcessSchema",
/* Type of business process to run. Run the business process without connection to a dedicated app page. */
"processRunType": "RegardlessOfThePage",
/* Save the current record before the business process is run. */
"saveAtProcessStart": true,
/* Display the notification when the business process is run. */
"showNotification": true
}
}
},
...
},
...
]/**SCHEMA_VIEW_CONFIG_DIFF*/,viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
/* Button that calls the business process. */
{
"operation": "insert",
"name": "SomeButton",
"values": {
...,
"clicked": {
/* Bind the sending of the base request to the "clicked" button event. */
"request": "crt.RunBusinessProcessRequest",
/* List of request parameters. */
"params": {
/* Code of the business process schema. */
"processName": "CodeOfSomeBusinessProcessSchema",
/* Type of business process to run. Run the business process for the selected list records. */
"processRunType": "ForTheSelectedRecords",
/* Save the current record before the business process is run. */
"saveAtProcessStart": true,
/* Display the notification when the business process is run. */
"showNotification": true,
/* The data source name. */
"dataSourceName": "PDS",
/* Key-value collection where key is the business process parameter and the value is the data source field. */
"parameterMappings": {
"SomeBusinessProcessParameter": "Id"
},
/* Filter selected list records. */
"filters": "$Items | crt.ToCollectionFilters : 'Items' : $DataTable_SelectionState | crt.SkipIfSelectionEmpty : $DataTable_SelectionState",
/* Sorting of selected records before they are passed to the business process. */
"sorting": "$ItemsSorting",
/* Track changes of the selected variable in data source. */
"selectionStateAttributeName": "DataTable_SelectionState"
}
}
},
...
},
...
]/**SCHEMA_VIEW_CONFIG_DIFF*/, - Go to the
-
Implement the base
crt.RunBusinessProcessRequest
request handler.-
Go to the
handlers
schema section. -
Add a custom implementation of the base
crt.RunBusinessProcessRequest
request handler.- Retrieve the instance of the HTTP client from
@creatio-devkit/common
. - Send the base
crt.RunBusinessProcessRequest
request that runs a business process. - Pass the required request parameters.
- Implement custom business logic that handles result and error of business process running.
- Retrieve the instance of the HTTP client from
View an example of the base
crt.RunBusinessProcessRequest
request handler that determines context and runs the business process below.handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.RunBusinessProcessRequest",
/* Custom implementation of a base request handler. */
handler: async (request, next) => {
/* Retrieve the instance of the HTTP client from "@creatio-devkit/common." */
const handlerChain = sdk.HandlerChainService.instance;
/* Send the base request that determines context and runs the business process. */
var result = await handlerChain.process({
type: 'crt.RunBusinessProcessRequest',
/* Code of the business process schema. */
processName: 'CodeOfSomeBusinessProcessSchema',
/* Type of business process to run. Run the business process for the selected app page. */
processRunType: 'ForTheSelectedPage',
/* Save the current record before the business process is run. */
saveAtProcessStart: true,
/* Display the notification when the business process is run. */
showNotification: true,
/* Name of the process parameter that is received by the record whose ID is specified. */
recordIdProcessParameterName: 'SomeBusinessProcessParameter'
});
/* If Creatio can run the business process, execute custom business logic. */
if (result.isSuccess) {
/* Implement custom business logic that handles result of business process running. */
...
} else {
/* Implement custom business logic that handles an error of business process running. */
...
}
/* Call the next handler if it exists and return its result. */
return next?.handle(request);
},
},
] -
See also
Display the value of a system variable
Element setup examples (user documentation)