Skip to main content
Version: 8.1

Run a business process using base request handler

Level: advanced

@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.

note

Creatio forbids running the business process that has output parameters in the background.

To run a business process:

  1. Add a button to run a business process from a Freedom UI page if needed. Instructions: Set up Button components (user documentation).

  2. Add the dependencies. Instructions: Display the value of a system variable (similarly to step 2). Instead of the SysValuesService service, use the ProcessEngineService service that lets you interact with business processes.

  3. Set up how to handle the action executed on button click.

    1. Go to the viewConfigDiff schema section → select required element. For example, SomeButton.
    2. Bind the sending of base crt.RunBusinessProcessRequest request to the element event. We recommend using the base crt.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., the processRunType parameter value, determines the entity with which the business process interacts. Learn more: Base request handlers.

    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*/,
  4. Implement the base crt.RunBusinessProcessRequest request handler.

    1. Go to the handlers schema section.

    2. Add a custom implementation of the base crt.RunBusinessProcessRequest request handler.

      1. Retrieve the instance of the HTTP client from @creatio-devkit/common.
      2. Send the base crt.RunBusinessProcessRequest request that runs a business process.
      3. Pass the required request parameters.
      4. Implement custom business logic that handles result and error of business process running.

    View an example of the base crt.RunBusinessProcessRequest request handler that determines context and runs the business process below.

    handlers schema section
    handlers: /**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)