The following examples provide a brief explanation about how to create a Business Rule using activity actions. Recall that at this point, you should have read the articles related with Data Access through Xpath and Business rules elements.
Creating Business Rules Actions
Imagine you have a Purchase Request Process. The first thing you need to do is set the Date of the request and the user creating it.
This can be done with an Action to set two values to two attributes of the data model.
We have two attributes created whose Xpath are: <PurchaseRequest.RequestDate> and <PurchaseRequest.RequestedBy>
1. To set a business rule that includes the information to those two attributes go to the fourth step of the Process Wizard and select Actions.
When the Process flow is opened click the first task of the Process.
On the Activity Actions window select On Enter and click the plus sign.
This will open a small window where you can select between On Enter, On Save and On Exit Actions. We will include an Expression.
Since conditional tasks do not need an incoming connector (process flow), No conditional task can have an On Enter behavior regarding Activity Actions.
2. The Expressions Manager will display.
Click New to create a new expression, or select and existing expression and click Edit to edit it.
3. Click New. The Expressions window will be displayed.
Give the new expression a Name, a Display Name and a description. We recommend to be as clear as possible in the display name and the description. This is very useful as your project grows and the number of expressions grow as well.
4. Right-click the black arrow to include en Expression Element which is the most complete element, that provides the maximum flexibility.
Give the element a name and click Ok. Keep in mind that complex rules might have a lot of Expression elements, so the name you give to each of them will help identify what you are doing and where you are doing it.
5. Double-click the new expression to open it.
We will set two attributes their initial values. So we will select each of them from the data model ONE AT A TIME.
Click the Data Model option on the upper left corner.
This will display the Data Model of your Process and you will be able to build the Xpath you need.
Click on the attributes and then click OK.
6. To assign today's date to the RequestDate attribute we will use a function found in the Functions list.
Click on the Functions menu, select the category Date & Time and select the function Today.
7. For the RequestedBy attribute we will select a function User Id found in the Current user information category.
8. Click on OK to save the Expression Element, and OK again to save the whole Expression.
When the a new case is created these two attributes will be automatically set with the values we gave them.
In the same Purchase Request Process, after the request has been created the Boss must approve it. At the end of the Activity we must create a record in a table to record the Boss' observations. The table must include the date, the user that approved (or rejected), the decision (if it was approved or rejected), and the observations.
We have a collection that stores the approval information whose Xpath is:<PurchaseRequest.PurchaseApproval>
1. To set the business rule that includes the approval information we create an Expression in the fourth step of the Process Wizard and select Actions.
When the Process flow is opened click the second task of the Process.
On the Activity Actions window select On Exit and click the Add sign to include an Expression.
Click New to create a new expression.
2. Give the new expression a Name, a Display Name and a description.
Right-click the black arrow to include en Expression Element and give it name. Then, double-click the new expression to open it.
3. We will declare a variable to be able to manipulate the addition of the new record of the collection.
Click on the Variables button and select New. On the new window click the Add sign and create an object variable.
Remember to always initialize variables, in this case we will initialize with null.
4. To use the variable created click the Variables button again and click the variable. It will be automatically included to the expression where the cursor is placed.
5. To assign a new record to the collection we will use a function found in the Functions list.
Click on the Functions menu, select the category Collections and select the function New collection item.
6. This will include the function to the expression. Now we have to replace the Xpath text with the Xpath of the collection.
To do this, click the Data Model button and select the Xpath collection.
7. Remove the angle brackets. Change the expression from:
NewApproval = Me.newCollectionItem("<PurchaseRequest.PurchaseApproval>")
NewApproval = Me.newCollectionItem("PurchaseRequest.PurchaseApproval")
8. Using the Functions button include the Me.setXPath function found in the Data navigation category.
Since we will be setting four Xpaths we will add four functions.
Replace the Me sentence with the attribute, replace the "Xpath" with the attributes from the collection to set and replace the value to set.
To easily replace the Xpaths, open the Data Model and navigate until you reach the attribute desired.
Copy it and then paste it on the expression.
The value to set can also be taken from the Data Model.
The Date will be taken from the Functions menu. Select the category Date & Time and select the function Today.
The approval User will be taken from the Functions menu. Select the category Current user information and select the function User Id.
The approved state will be taken from the data model, that is a state chosen by the Boss.
The Observations will be taken from the data model, those are included by the Boss.
9. Click on OK to save the Expression Element, and OK again to save the whole Expression.
When the case exits the Approval task a new record in the Approval collection will be added and updated.
Relating an Action to a Sub-Process
To include an Action to a Sub-Process shape just hold the Shift key and then click the shape. This will open the shape's Actions.
If you click the Sub-Process shape without holding the shift key, the Sub-Process flow will be displayed to include Actions on its shapes.