You are forwarded to the overview of the functions of the business object. There you can go to the function details, edit a function, test it, copy or delete it.
To add a new function, click on the ‘+’.
It’s best practice to wrap your main code block in a try-catch-block to handle possible errors.
Let’s have a typical hello world example:
In the toolbar above you have several possibilities:
- undo (ctrl+z)
- redo (ctrl+y)
- search (ctrl+f)
- search and replace
- format code
- validate code
- settings (ctrl+,)
This example reads a name that is provided to the business object as an input parameter, compiles it into a greeting message and writes the result to the output.
Take a look at the try-catch-block surrounding the main code section:
If no error occurs, the upper part of the code inside the “try”-section will execute and return the greeting message and output.success = true. However, if any error occurs, the function will jump down into the “catch” section and return output.success = false and assign any details of the failure to attribute output.error.
In order to use the script function correctly, you have to add the same input and output parameters you used in the payload. Those parameters will be shown in the mapping dialogs in the Process Designer. Please note the corresponding handling of in- and output through the (JSON) objects “input” and “output”. Both of them may carry arbitrary attributes.
In this example the object “input” carries the attribute:
- input.name to read the inserted name.
The “output” object carries the attributes:
- output.message to send a greeting message.
- output.success (true/false) to indicate whether the script template executed successfully.
- output.error to hold the root cause of an error in case of failure.
You can validate the input and output parameter in the backend. It validates:
- Base type against type security
- Domain type against security and restrictions
- Structures against type security and underlying property types
- Collections against type security and the underlying types/property categories
If the validation is not successful, the client is notified of all failed validations and it’s written to the business object log or system log at the same time.