IBM Business Automation Workflow V184.108.40.206 offers decision tasks which can be implemented as action rules and decision tables. This scenario shows how to create and test action rules (Business Action Language (BAL)) and decision tables in a decision task. The scenario presents a sample business process that is used to correctly determine the value added tax (VAT) for different kinds of goods in different countries.
Before you begin
To perform this task you must be in the web based IBM Business Automation Workflow Process Designer.
About this task
We look at the following scenario, a company sells various types of goods. It is selling in various European countries. When such a company sends out an order, the bill needs to be aligned with local regulations, for example, it needs to contain the payable amount with tax, and without tax.
Depending on the country, the value added tax (VAT) depends on the type of the goods. In Germany, value added tax for books is just 7 percent, while for other goods it is 19%. Belgium, for example, has a VAT on food of 6% and 21% on everything else.
The company needs to compute the value added tax depending on the country and the product type.
There is already a process in place that computes the payable amount with and without tax. We add action rules for the different types of product and per country. Thereafter, we use a decision table for the same computation.
The process has a simple interface to take as input how many of an item were bought to which price per item. The country of the purchase is set via a dropdown list.
The first screen shot below shows the used variables, the second screen shot shows the process itself. The system service “Compute VAT” either uses action rules or a decision table to compute the VAT. MyComputeVAT is built to gain experience in constructing action rules and decision tables. Later compare MyComputeVAT with the original Compute VAT.
Import the Pricing – Start.twx file which you can download here.
- Open the IBM Business Automation Workflow Process Center.
- On the right hand side click on Import Process App.
- Select the Pricing – Start.twx file and Open.
- In the Import Process App window click on Import. The Pricing process opens in the designer view.
To add a decision service to a process, complete these steps:
- Open the web based IBM Business Automation Workflow Process Designer.
- From the left hand navigator choose Services, click on the + sign, choose Service flow, give it a name like “MyComputeVAT” and click Finish. A diagram with connected start and end nodes is shown.
- The right hand navigator shows different options. Click on the down arrow of the top rectangle to see the choices for tasks and click and hold on Decision to drag a decision task between the start and end node.
- Click on the decision and give it the name Action Rules.
- Wire the start node to the decision task and from there to the end node.
- Click on the existing connection and then press delete. Then wire from the Start node to Action Rules and from there to End.
- Define the input and output variables of the decision task
- Click on Variables and then the + sign for Input to add an input variable.
- Give it the name product and choose as Variable type Product (predefined type).
- Add another input variable and name it country of type String.
- Add an output variable and give it the name taxrate of type Decimal.
- Press CTRL-s to save your work.
- Define the decision task
- Click on Decisions at the top and then on Action Rules in the left hand navigator. The decision action rule editor opens and shows an if <condition> then <action> rule and a message that the rule is incomplete.
- Click on <condition> and a box with choices opens, choose country, press the spacebar and then CTRL-spacebar; another choice box opens, choose is <an object >. CTRL-spacebar again and choose <string>, enter Germany between the quotes.
Add a space after the last quote and press CTRL-spacebar again and choose and <condition>. Again add a space and press CTRL-spacebar and choose any of the following conditions is true :. Press CTRL-spacebar again and choose -<condition>. Press CTRL-spacebar again and choose the type of <a product>, CTRL-spacebar choose product, CTRL-spacebar choose is <an object>, CTRL-spacebar choose BOOK.
- Now add a second condition where the type of product is FOOD.
- Click on <action> and choose set <variable>, choose taxrate, next choose
to <variable value> and finally choose <number> and set it to 7.
- Press CTRL-s to save your work.
The choice of the product type works because the type ProductType has already been defined as a Simple type of type Selection when the Pricing – Start.twx file was imported.
So far we have achieved that there is a rule that determines the VAT correctly when books or food is bought. In order to set the VAT to 19% in all other cases we need an additional rule:
if country is “Germany” and none of the following conditions are true :
– the type of product is BOOK
– the type of product is FOOD
then set taxrate to 19 ;
An additional action rule can be added by clicking on the Add action rule rule icon, the top icon on the right hand side of the existing action rule. Use the up and down arrows to determine the order in which the rules are checked. Use the description above to create the additional action rule for all the cases where neither book nor food is bought. Press CTRL-s to save your work.
Your MyComputeVAT action rules decision should look as follows:
For countries like Sweden which have three different VAT rates, for books (6%), food (12%), and everything else (25%) three action rules are needed.
Decision tables offer a different way to model these rules which is explored now. Add another decision to the existing service flow.
- If not still open, navigate to the MyComputeVAT service flow where we added the decision that was modeled as action rules. Click on Diagram at the top to open the flow editor.
- Add a second decision onto the canvas by dragging a decision task from the right hand navigator onto it. Give it the name Decision Table. Wire it to the end node. Your service now looks as follows:
- Click on Decision Table and then on Open Decision in the Implementation tab at the bottom of the page. The decision editor opens with an empty if-then rule.
- Click on the X on the right hand navigator to delete that rule.
- Mouse over the icons at the top on the right hand side and click on add a decision table. A table with two columns opens, a condition column, C0, and an action column, A0.
- Right click on the C0 and choose Insert column -> Condition after. A second condition column, C2, is shown. Rename the columns as follows
- Double click on the label C0 and enter the text Country.
- Double click on the label C2 and enter the text Product type.
- Double click on the label A0 and enter the text Value-added tax rate (%).
- Next the values that can occur in a column need to be defined.
- Right click on the column label of the first column “Country”, choose Define column. The Define Condition Column editor opens, click in the white space and hit CTRL-spacebar. A box opens with the available options. Choose the variable country press CTRL-spacebar again and choose is <an object>:. Click on Define at the bottom of the editor window, the column content is now defined.
- Right click on the label of the second column “Product type”. Choose Define column. In the open editor window click on the white space and then hit CTRL-spacebar. From the options choose the type of <a product>. Click on
<a product> and choose the variable product. Add a space and hit CTRL-spacebar again and choose is <an object>. Then click on <an object> and choose <a product type>. When you are done click on Define at the bottom of the editor window and the column is defined.
- Right click on the label of the action column and choose Define column. Define the column as “set taxrate to <a number>”. Click Define at the bottom of the editor and then CTRL-s to save your work.
- The tax rate per object type and country can now be defined.
- Click and hold the first cell in the Country column and move the mouse down such that you mark the first three rows of the Country column.
- Right click the marked rows and choose Group from the options.
- Double click the first cell of the Country column and enter Germany. Click anywhere outside the cells. All cells now have the same value.
- Double click into the first cell in the Product type column and choose Book from the drop down menu.
- Double click into the first cell of the Value-added tax rate (%) column and enter the number 7.
- In the second row Germany is already entered, so add the values, FOOD, and 7 into the respective columns.
- In the third row right click in the second cell and choose Set to Otherwise from the options menu.
- In the cell of the third row for the Value-added tax rate (%) enter 19.
- Press CTRL-s to save your work.
You can check the rules for every row of the table by hovering the mouse over the row number. It is very easy to add new countries and their rules for the tax rate depending on different product types.
Run your implementation
In the process designer navigate to the Processes on the left hand side and click on Print Bill.
In the Definition tab of the process click on the Compute VAT system service. In the properties section at the bottom click on the Implementation tab and select as implementation the MyComputeVAT service. The resulting VAT is the input to the ShowBill human service that computes the prices with and without tax via a script and then displays them to the user.
As the readily made process Pricing – Start.twx was imported with the Compute VAT which has just been replaced with the MyComputeVAT service the data mapping has to be adjusted.
- In the properties section at the bottom click on Data Mapping.
In order to try out the implementation navigate to the processes on the left hand navigator of the Web Process Designer and click on the Print Bill process. At the top of the page there is a small arrow in a circle pointing to the right that shows Run when the mouse is hovering over it. Click it to run your process.
- On the right hand side new elements open, Details, Tasks, Locations, Data. Details and Locations are already expanded. The process shows a token at the position of the Purchase an item task.
- In the locations area on the right hand side click on the start arrow for the Purchase an item task.
- The input window opens and you can enter your information. When done click the ok button at the bottom of the page. Remember that from the offered countries you can only choose Germany as there are no rules for the other countries (yet).
- The input window shows the message “The service has finished”. Close that window.
- The process now shows a token at the Show Bill position. Sometimes it shows a token at the MyComputeVAT node. If that happens, click on the start arrow on the right hand side in the locations area and the token will move further on to the Show Bill task.
- In the locations area on the right hand side click on the start arrow for the Show Bill task.
- The Show Bill window opens and shows the appropriate prices with and without VAT.
- Click the ok button at the bottom of the window and then close the window to finish the process.
Go to the Services tab on the left hand navigator again and click on MyComputeVAT. Click on Diagram and change the endpoint of the arrow from Start to Decision Table instead of to Action Rules, save your change and run the process again.
When you are done with testing your decisions you can try out the original Compute VAT Service. It contains more countries and rules for adding VAT onto different goods. In order to try out more countries than the four offered in the drop down box you will have to add them to the drop down box as shown in this screen shot.
- In the left hand navigator click on User Interface and then on Enter order UI. Click on the Coaches tab at the top and then on Coach at the left.
- Click on Country and in the properties section at the bottom on Configuration.
- From the three elements Behavior, Items, and Appearance, click on Items. Scroll down a bit and click on the twisty left of Static list.
- The list of elements that are shown in the drop down box is shown and you can add more countries right there. When done save your work by pressing CTRL-s and continue with your tests.
Decisions can also be used to model the conditions of an exclusive gateway which determine the subsequent path through a process or service flow (see also using a decision service in an exclusive gateway). The use of decisions for modeling the conditions for an inclusive gateway is restricted to process flows.
Depending on the task it may be easier to use action rules or decision tables. Offering both allows for maximum flexibility. Furthermore, you can export the decisions as a project file for use in IBM Operational Decision Manager (ODM) (see importing a project).