Business Process Designer > Business process modeling > Graphical elements / Script

Script

A script is a TypeScript code that allows you to access business process data, create, query, modify and delete app items, as well as exchange data with external systems using the HTTP protocol.

Suppose a company sells products online through a website. When a client clicks Place order, a script is executed. This script launches a business process in QuickBPM and the information about new order is sent to the process. The program automatically calculates the discounts and the total, and then sends the data back to the website.

How to add Script to the process

начало внимание

Only users included in the Administrators group can manage Script settings.

конец внимание

On the process page,  to the right of the modeling sheet, find the Standard elements tab. Drag the Script activity to the process diagram and place it where required.

1.PNG

Double-click on the Script activity to open the settings window. It contains two tabs: General and Error Handling.

2.PNG

General Tab

3.PNG

In the Name field, specify the name of the operation as it will be shown in the system, for example, Calculate total amount.

In the Function field, you need to select or add a function. Functions previously added to the process are available in the drop-down list. If you need to create a new one, click Create. Specify its name using English letters, numbers, and the underscore. The function's name must begin with a letter. Click Create and then click Open.

4.PNG

You will be redirected to the Scripts Tab. There you can write the script that can access context variables and automate certain operations.

начало внимание

Scripts are written in TypeScript programming language. To learn about the basic principles of scrip-writing in QuickBPM, please visit our TypeScript SDK Help Center.

конец внимание

04.PNG

In certain scripts, you can use additional parameters. They allow you to optimize some process operations or make changes to the script without republishing. You can read more about this in the Additional Parameters article.

After writing the script, you can check it. If there are any errors, for example, an app is missing in the process context, the editor will underline them. A script with errors cannot be published.

7.PNG

Error Handling Tab

You can define the program behavior in case of process errors, for example, if QuickBPM fails to reach an external service.

To do this, open the Error handling tab in the settings window.

8.PNG

 

  • Retry - select this option if you want the system to re-execute the script.
    • Number of retries - indicates how many attempts the system must take to re-execute the script.
    • Retry delay (sec) - determines the amount of time QuickBPM should wait before trying to re-execute the script.
  • Notification - select this option if you want to inform specific users about a script failure.
  • Interrupt - in case of an error, QuickBPM will interrupt the execution of the script and resume the process. You need to select a connector to specify which process branch should be activated.

After you specify all the settings, click Save.