Help ELMA BPM Platform
×
Menu

Script Emulation

You can emulate a script to make sure that it works as expected. You can also test how the script works with different values of the process context.
To emulate a script, you do not have to publish the process. However, when a script is emulated, it works exactly as it would work in a published process. It is rather convenient that the operations of the process preceding the script do not have to be executed. Moreover, the emulation mode makes it possible for ELMA not to store the data of the test execution of the process.
Emulation is done within the context, but task forms of the process cannot be loaded in emulation mode. Due to this, you cannot test the dynamic forms of the process.
To start emulation, go to the Scripts tab of the business process page (Fig. 1).
Then click Start Emulation in the toolbar.
Fig. 1. Scripts tab of the process page. Start Emulation button.
Emulation is performed in ELMA Web Application (Fig. 2).
Fig. 2. Starting emulation in Web Application.
If the Script Emulation page does not load, check if the server address and port specified in the address field are correct. If not, change them manually or configure Designer connection settings in General Settings and configuration settings in the Designed main menu.
In the Debugging Parameters section, select the script that you want to emulate and specify if recovery of all changes made by the script is needed. The list of scripts shows all the scripts of the current business process.
Use the Recovery feature to specify how emulation is executed.
 
Yes - all changes made by the script will be cancelled when the script is executed: all the created variables will be deleted, and all the existing variables will be reset to their initial values. If the script creates any object instances, they are also deleted.
 
No - all changes made by the script will remain in the database after the script is executed.
In the Context section you can specify the values of the context variables, which will be used in the current script.
When you have made all the abovementioned adjustments, click Start Script in the toolbar. If the are no errors, the "The script is executed" notification will appear on the Script Emulation page (Fig. 3).
Fig. 3. Script executed without errors.
If there are any errors in the script, the error notification appears (Fig. 4). The Error Description section usually indicates the line where the error was found (Fig. 4).
Fig. 4. Error notification.
If the script changes the context of the business process, the new values of the context variables will be available in the Context section after emulation.
To reset the values of the context variables, click Reset Context in the toolbar. This feature is used when you need to emulate the script with new initial values.

Advanced features of script emulation

Sometimes, script emulation requires more than simple testing of context variables. ELMA has additional features that make debugging more flexible.
Show text in console
By default, users do not see the console that shows the script execution result. However, you can add a command to your script for the text to be shown in the console. The command looks as follows:
this.Console.WriteLine("This text will be shown in the console");
With this command, any information you like can be shown in the console.
If there is at least one command of this type in the script, the Script Emulation page shows an additional section titled Message Console (Fig. 5). There, you can see the contents of the console.
Fig. 5. Message Console in Script Emulation.
When scripts with such commands are executed in process instances, users do not see these messages, because user task forms cannot display consoles.
Showing error message
If you want the script to handle certain errors, you can use commands that show error notification:
throw new Exception("Error text");
When the script with this line of code is emulated, you will see the Error executing script notification in the top part of the page, showing the text specified in the Exception method (Fig. 4). A full description of the error, including the line where the error was found, is given in the Error Description section.
Debug code
To make debugging even more flexible, ELMA allows you to add debug code to your script. These pieces of code are only executed in debugging mode. When the script is executed in the process in Web Application, ELMA ignores these pieces of code, like it ignores code comments.
Debug code is written in the following way:
if (IsDebug)
{
  // All the code inside these braces is executed
  // in debugging mode only.
}         

Copyright © 2006–2019 ELMA