An interruption is a human intervention to change the normal flow of a business process. The Tahiti application needs to handle modification or cancellation of a vacation request. These are interruptions triggered by an employee. You will enable a user to modify a pending vacation request, and to cancel a pending or approved vacation request. The user’s manager must approve cancellation of a request that has already been approved. If a user wants to modify an approved request, they can cancel the approved one and submit a new request. This chapter explains how to extend the Tahiti application so that employees can modify a pending vacation request, or cancel a request.
A user can modify a pending vacation request. In the Tahiti application prototype page that you have created, when the user selects a pending vacation request, a button marked Modify Vacation Request appears, together with fields to change the dates and duration of the vacation request. A user can only change a pending request, so there is no manager review step.
In this section, you will:
This section explains how to add fields to the Tahiti application page that the user can use to modify a pending vacation request. The user modifies the vacation request in the application page, then clicks a button to submit the change. There is no need for a separate form for updating the request. It is more efficient for the user to make the change directly in the application page.
Follow these steps:
processModify
with the following value:../API/bpm/process?s=Modify Pending Vacation Request &p=0&c=10&o=version&f=activationState=ENABLED
Create a JavaScript expression variable called urlStartModifyProcess
with the following value:
// Return the API URL to instantiate the modify vacation request
// process
if
(
$data
.
processModify
&&
$data
.
processModify
.
length
>
0
)
{
return
"../API/bpm/process/"
+
$data
.
processModify
[
$data
.
processModify
.
length
-
1
].
id
+
"/instantiation"
;
}
else
{
return
null
;
}
Add a Text widget with the following properties:
Text | To modify the selected vacation request, update the details in the selected request line, and then click <b>Modify selected vacation</b>. |
Hidden | Bind to selectedRow.copy.status!=="pending” |
Move the “Modify selected vacation” button into a row beside the Text widget that you have just added, and update the following properties:
Disabled | no |
Action | POST |
URL to call | {{urlStartModifyProcess}} |
Data sent on click | Bind to {"vacationRequestIdContract”: selectedRow.copy.persistenceId_string, “startDateContract”: selectedRow.copy.startDate, “returnDateContract”: selectedRow.copy.returnDate,"numberOfDaysContract”:selectedRow.copy.numberOfDays} |
Target URL on success | /bonita/apps/tahiti/index/ |
Add an Input widget with the following properties:
CSS classes | visibility: hidden |
Value | Bind to urlStartModifyProcess |
To modify a request, the user selects the request in the table. The information in the selected row is copied to the Start date, Return date, and Number of days widgets. If the status of the selected request is Pending, the “Modify selected vacation” button appears. The user updates the dates and number of days, then clicks the button. Clicking the button triggers an API call that starts an instance of the process to modify the vacation request. The next section explains how to define this process.
To create the process that enables users to modify a vacation request, you need to do the following:
Create a new diagram called Tahiti-ModifyPendingVacationRequest. Name the pool Modify Pending Vacation Request. The pool needs to contain an Employee lane, which is created by default. In this lane, add:
Service tasks named
Your diagram should look something like Figure 11-1.
There is no need for a review step, because the pending request is already the subject of an instance of the process to review a new vacation request. When the manager reviews the request, she will see the updated information. You do not need to create an instantiation form because the process is started by an API call that provides all the data that is needed.
When you view the validation status, there are warnings about forms that are not defined. To remove the flag warning that no instantiation form is defined, select the pool, go to the Details panel, Execution tab, Instantiation form pane, and check “No form.” You can do the same to remove the warning that no Overview page is defined.
For Modify Pending Vacation Request, the process contract contains these inputs:
Input name | Type | Description |
---|---|---|
vacationRequestIdContract | TEXT | The ID of the edited vacation request. |
startDateContract | DATE | The new value for the first day of vacation. |
returnDateContract | DATE | The new value for the day the requester returns to work. |
numberOfDaysContract | INTEGER | The new value for the number of days of vacation, not including nonworking days. |
In the Inputs tab, specify the attributes required. For each one:
Add a business variable, vacationRequest
, as follows:
vacationRequest
.VacationRequest
.VacationRequest
.In the Queries drop-down list, select findByPersistenceId
. The query is displayed in the Query content box. You do not need to change this. However, for the query to work, you need to define a script that converts the ID from a String (the type used by the contract) to a Long (the type needed for the search query parameter). Do this as follows:
persistenceId
parameter.return
Long
.
valueOf
(
vacationRequestIdContract
)
Add a business variable, vacationAvailable
, as follows:
vacationAvailable
.Add the process variables numberOfDays
(Integer), startDate
(Date), and returnDate
(Date) as follows:
Now you need to define operations to update the counter of available days for the requester and to update the pending request:
Select the Find vacation available step, go to the Details panel, Execution tab, Operations pane and define an operation to initialize the vacationAvailable
business variable:
vacationAvailable
.VacationAvailable
.findByBonitaBPMId
. The query is displayed in the Query content box.persistenceId
parameter.vacationRequest
.VacationRequest - getRequesterBonitaBPMId
.Select the Update vacation available step, go to the Details panel, Execution tab, Operations pane and define an operation to update the daysAvailableCounter
according to the modification made by the requester:
vacationAvailable
.setDaysAvailableCounter
, and click OK.calculateNewDaysAvailableCounter
.Enter this script:
vacationAvailable
.
daysAvailableCounter
+
vacationRequest
.
numberOfDays
-
numberOfDays
Select the Update vacation request step, go to the Details panel, Execution tab, Operations pane and define an operation that uses the value of the process variable that stores the modification made by the requester to update the numberOfDays
:
vacationRequest
.setNumberOfDays
, and click OK.numberOfDays
.startDate
and an operation to update the returnDate
.This completes the definition of the process to modify a pending vacation request.
When a user cancels a vacation request before it is approved, the process that was previously started to approve the request must be stopped. If the request is already approved, the manager needs to approve the cancellation, in case the employee is not using up vacation days correctly.
The starting point for cancelling a vacation request is the vacation statement that you created in “Create the Application Prototype” and updated in the previous section to enable pending requests to be modified. The employee selects a vacation request in the table and clicks the Cancel button, which starts the cancellation process.
In this section, you will:
This section explains how to add a button to the Tahiti application page that the user can use to cancel a vacation request. A request can be cancelled if it is pending or approved. The user selects the vacation request in the application page, then clicks a button to submit the cancellation request. There is no need for a separate cancellation form. It is more efficient for the user to make the change directly in the application page.
A request that is pending is cancelled immediately when the user clicks the Cancel button. For an approved request, manager approval is needed, so the vacation request goes into a special state, processing cancellation, until the cancellation is approved or refused.
To update the application page, follow these steps:
processCancel
, with the following value: ../API/bpm/process?s=Cancel Vacation Request&p=0&c=10&o=version&f=activationState=ENABLED
Create a new JavaScript expression variable called urlStartCancelProcess
, with the following value:
// Return the API URL to instantiate the cancel vacation request
// process
if
(
$data
.
processCancel
&&
$data
.
processCancel
.
length
>
0
)
{
return
"../API/bpm/process/"
+
$data
.
processCancel
[
$data
.
processCancel
.
length
-
1
].
id
+
"/instantiation"
;
}
else
{
return
null
;
}
Add a Text widget with the following properties:
Text | To cancel the selected vacation request, click <b>Cancel selected vacation</b>. If the request is already approved, a cancellation request will be sent to your manager. |
Hidden | Bind to !(selectedRow.copy && selectedRow.copy.status!=="refused”) |
Move the “Cancel selected vacation” button into a row beside the Text widget that you have just added, and set the following properties:
Disabled | no |
Action | POST |
URL to call | {{urlStartCancelProcess}} |
Data sent on click | Bind to {"vacationRequestIdContract”: selectedRow.copy.persistenceId_string} |
Target URL on success | /bonita/apps/tahiti/index/ |
Add an Input widget with the following properties:
CSS classes | visibility: hidden |
Value | Bind to urlStartCancelProcess |
You now have the final version of the Tahiti application page. Export it by clicking the Export icon in the top bar. This creates a .zip archive that you will deploy later, in “Update the Application”.
You need to define a process to handle the cancellation request. It checks whether the request to be cancelled is pending or approved. If it is approved, it presents the manager with a form to review the cancellation. If the request is pending, it sends a message to the active New Vacation Request process to cancel the request. You need to update the New Vacation Request process to receive the message and take the actions needed to cancel the request.
To create the cancellation process, you need to do the following:
The following sections explain how to do this.
For Cancel Vacation Request, the process contract contains only one input, vacationRequestIdContract. To define the contract:
vacationRequestIdContract
, in the Name column.cancellationApprovedContract
. To define the contract:
cancellationApprovedContract
, in the Name column.Add a process variable, cancellationApproved
, as follows:
cancellationApproved
.Add a business variable, vacationRequestToCancel
, as follows:
vacationRequestToCancel
.VacationRequest
.VacationRequest
.In the Queries drop-down list, select findByPersistenceId
. The query is displayed in the Query content box. You do not need to change this. However, for the query to work, you need to define a script that converts the ID from a String (the type used by the contract) to a Long (the type needed for the search query parameter). Do this as follows:
persistenceId
parameter.stringToLong
.Enter the script content by copying this:
return
Long
.
valueOf
(
vacationRequestIdContract
)
Add a business variable, requesterVacationAvailable
, as follows:
VacationAvailable
.Now specify how the cancellationApproved
variable is updated with the manager’s decision. This is done with an operation on the Review cancellation human task, as follows:
cancellationApproved
.cancellationApprovedContract
.An actor defines who can carry out the tasks in a lane. For the Employee lane, the Employee actor is specified by default so you do not need to do anything. For the Manager lane, configure an actor and actor filter as follows:
Configure the Send message to cancel request throw message event. This event sends a message to the New Vacation Request process that is in progress for the vacation request that the user wants to cancel. Follow these steps:
requestId
.vacationRequestToCancel
, and in “Browse your Java object” select VacationRequest
getPersistenceId
.This section explains how to set flow conditions on the gateways in the Tahiti-CancelVacationRequest process diagram:
Set conditions on the outbound flows of the Status of request gateway:
Select the Pending flow, go to the Details panel, General tab, General pane, and select “Use expression.” Click the pencil icon to open the expression editor. Create a Script expression called isRequestStatusPending
with the following content:
return
vacationRequestToCancel
.
status
==
"pending"
Select the Approved flow and click “Use expression.” Click the pencil icon to open the expression editor. Create a Script expression called isRequestStatusApproved
with the following content:
return
vacationRequestToCancel
.
status
==
"approved"
Set conditions on the outbound flows of the Cancellation approved? gateway:
cancellationApproved
variable.When a cancellation request for an approved vacation request is being processed, there are the following changes to the vacation request status:
The service task Set vacation request status to “processing cancellation”, which is in the flow for handling cancellation of a request that is already approved, changes the request status to indicate that a cancellation is in progress. Follow these steps:
vacationRequestToCancel
.setStatus
, and then click OK.Next, update the vacation request status for a request when the manager refuses the cancellation. Select the Reset vacation request status to approved service task, then follow the same steps as for the Set vacation request status to “processing cancellation” but for this task set the status to approved.
Finally, update the vacation request status for a request when the manager approves the cancellation and when a pending request is cancelled. Select the Update vacation request status service task, then follow the same steps as for the Set vacation request status to “processing cancellation” but for this task set the status to cancelled.
Update the number of days of vacation that the user has after a successful cancellation. This is done in two service tasks, Get vacation available, which gets the current number of available days, and Credit vacation available, which updates this total by adding the number of days that were assigned in the cancelled vacation request.
First, configure Get vacation available, as follows:
requesterVacationAvailable
.VacationAvailable
. This automatically sets the Query to findByBonitaBPMId
. The query definition is displayed.In the Parameters box, the query parameter, bonitaBPMId
, is listed. You need to specify the value for this, which you do with another expression:
vacationRequestToCancel
from the Name list, choose getRequesterBonitaBPMId
from the object tree, and then click OK.Next, configure Credit vacation available, as follows:
requesterVacationAvailable
.setDaysAvailableCounter
, and then click OK.Enter the following script:
requesterVacationAvailable
.
daysAvailableCounter
+
vacationRequestToCancel
.
numberOfDays
java.lang.Integer
, then click OK to save the definition.This completes the diagram for the cancellation process.
Next, update the Tahiti-NewVacationRequest process to receive the cancellation message from the Tahiti-CancelVacationRequest process and delete the pending request. Follow these steps:
Select the catch message boundary event again, and configure it:
vacationRequest
object in the Name column, then in the “Browse your Java object” box, click getPersistenceId()
.This completes the update to the New Vacation Request pool, and in particular to the reviewRequest
task. When you have finished, this part of the diagram should look something like Figure 11-3:
This process is started by an API call when an employee submits a cancellation request. The request contains all the information that is needed, so there is no instantiation form. To remove the flag warning that no form is defined, select the pool, go to the Details panel, Execution tab, Instantiation form pane, and check No form. You can do the same to remove the warning that no Overview page is defined.
You do need to create the form that the manager will use to review cancellation requests for previously approved vacation requests. This form needs to return the manager’s decision to the process, so this is stated in the contract. It also needs to present the manager with the information needed to make the decision; that is, the details of the vacation request and the number of unbooked vacation days that the user has.
To create the contract and the default form, follow these steps:
cancellationApprovedContract
.The form that is created automatically contains only two widgets: one to capture whether or not the reviewer approves the cancellation, and the other a Submit button. To make the form useful you need to define some variables and add widgets to display information about the user who is requesting the cancellation and about the request that is to be cancelled.
This section explains how to add the variables that are necessary for the cancellation review form. Follow these steps:
vacationRequestBusinessData
with the API URL ../{{context.vacationRequestToCancel_ref.link}}
. This variable uses the reference to the request to be cancelled that is provided automatically in the context, and retrieves the request details.requester
with the API URL ../API/identity/user/{{vacationRequestBusinessData.requesterBonitaBPMId}}
. This gets the ID of the user requesting the cancellation.requesterCurrentDaysAvailable
with the API URL ../API/bdm/businessData/com.company.model.VacationAvailable?q=findByBonitaBPMId&p=0&c=1&f=bonitaBPMId={{vacationRequestBusinessData.requesterBonitaBPMId}}
. This uses the requesterBonitaBPMId
from vacationRequestBusinessData
to get the current number of available days of the requester.Now you can add widgets to the form to display the information about the user and the request using the variables that you have just defined. Follow these steps:
Add widgets to present the details of the request that the user wants to cancel. Put the three widgets that display the request details on the same line.
Start date:
Widget type | Datepicker |
Width | 4 |
Read-only | yes |
Label | Start date |
Value | vacationRequestBusinessData.startDate |
Return date:
Widget type | Datepicker |
Width | 4 |
Read-only | yes |
Label | Return date |
Value | vacationRequestBusinessData.returnDate |
Number of days:
Widget type | Input |
Width | 4 |
Read-only | yes |
Label | Number of days |
Value | vacationRequestBusinessData.numberOfDays |
Add a Radio buttons widget called Decision for the reviewer to specify whether they approve or refuse the cancellation request. Set the properties as follows:
Set the Available values property to:
[{
"display"
:
"Approve cancellation"
,
"value"
:
true
},
{
"display"
:
"Refuse cancellation"
,
"value"
:
false
}]
You have now created the form that managers will use to review cancellation requests.
To test the processes and updated pages, follow the steps in Chapter 10, but this time deploy all the processes, as well as the new TahitiVacationManagement page.
In this chapter, you have updated the Tahiti application to enable users to modify and cancel vacation requests, and added the process required to handle these changes. You have now created three diagrams, Tahiti-NewVacationRequest, Tahiti-ModifyPendingVacationRequest, and Tahiti-CancelVacationRequest, and downloaded a process to initialize data for testing.
In the next chapter, you will configure service tasks to send email and update calendar events during these processes.
18.219.215.178