Add a new BeanShell Script Action
Overview
This tutorial will guide you through the process of adding a new BeanShell action. In this example, we will replace an existing assign action with a custom BeanShell script. We will be using Void Transaction scenario.
What you will learn
How to add a new BeanShell Script Action.
Pre-requisites
Should have followed Training Workspace Setup and have a working POS.
Exercises
Perform a Transaction void
From this, we are going to ensure beforehand that a Transaction void can be performed correctly from the POS.
Login to POS using the following credentials
Username = 1010
Password = 1010
Add Product 1 to the basket.(Type 1 on the input box and click enter).
Now, click Voids button and select Void Transaction.
Select "Customer Left Store" from reason list.
Press OK and there should not be any product in the Transaction Basket.
Overriding an existing Process
Using process Sets we can override an existing application process. Refer Process Set for more details.
In this tutorial, we will use the EndTransaction_1.0.xml process, originally from the POS - POS
project, and override it in the Training Build - pos
project.
EndTransaction_1.0.xml process will be used in Transaction Void.
Populate folder structure as below in the Training Build - pos
project. For more information refer Create new Process Set.
|-- "src"
| |-- "META-INF"
| | `-- "deployments"
| | `-- "Process"
| | `-- "Training"
| | `--"Pos"
| | `--"Transaction"
Then, Open the resource Library by navigating to Window -> Show View -> Resource Library.
Search for the process EndTransaction on the search bar.
Double click and open the process.
From the project Explorer view, right click on the process file and select enactor -> Copy Resource
Then go back to the Transaction folder created above, right click and select enactor -> Paste Resource
The final project hierarchy should be as below.
Open the newly generated process using the process editor.
Now, right click on the process and select show properties. See whether Process ID has changed properly to Training/Pos/Transaction/EndTransaction
.
Adding a new Beanshell Script Action
Open the EndTransaction_1.0.xml process.
Then open the palette by navigating to Window -> Preferences -> Show View -> Palette. Drag and drop an Execute BeanShell Script action from Advanced Actions category to the newly created EndTransaction Process.
Right click on the added action and select show properties.
In the properties tab, give "AddAssignments" as the Action ID.
Here we are going to replace the Init assign action with the AddAssignments BeanShell Script action.
Double click on the input section of the AddAssignments Beanshell Script action and add the same inputs used in the assign action. Similarly, update the output section by adding the same outputs used in the Assign action.
For outcomes, double click on the Outcome section and add "Success" as an outcome to the beanshell script action.
As the Assign action is being replaced, it is important to reconnect the same incoming and outgoing links to the AddAssignments Beanshell Script action to maintain correct process functionality.
Therefore click on Link from palette and connect the Success outcome of AddAssignments action to the GetTransactionVoidItem action.
Also, change the input conditional link which is connected to assign action from IsRetailTransaction action,by dragging the endpoint of it from the assign action to AddAssignments beanshell script action.
Finally the process diagram should look as below.
Adding the Script
There are two assignments in the above assign action, which we need to write the AddAssignments beanshell script in order to do the same assignments.
For this, double click on the AddAssignments beanshell script action and open the script editor.
We can rewrite the assignments in beanshell scripts (Java Like Script). The outcome should also be added.
if (retailTransaction != null) {
isTrainingMode =( (!retailTransaction.trainingDetails.isEmpty()) && retailTransaction.trainingDetails.trainingMode);
transactionReversal = retailTransaction.isTransactionReversal;
}
outcome ="Success";
Copy and paste the above script on the script editor and click OK.
Save the changes.
Perform a Transaction void using the BeanShell Script action
Perform a Transaction Void again by following the steps in Transaction Void and ensure that the functionality works as expected.