Skip to Content

Effective Ways of Using Intermediate Timer with Human Task in BPM

November, 2012

Prerequisites: 

§  Basic knowledge of SAP NetWeaver BPM

§  Basic knowledge of SAP Java Webdynpro

§  Basic knowledge of EJB

§  Basic knowledge of SAP NetWeaver Portal.

Introduction:

This article will tell you how to effectively use an Intermediate Timer with the Human Task in BPM process.

Contents

1.0  Create Process DC

2.0  Create Process

3.0  Create Pool

4.0  Effective way of using the Intermediate Timer with Scenario One

5.0  Effective way of using the Intermediate Timer with Scenario Two

6.0  Steps to start the process

1.0 Create Process DC

Go to Process Composer perspective. New –> Process Composer Development Component.

/wp-content/uploads/2012/11/fig1_161036.jpg

Provide name for the process DC.

/wp-content/uploads/2012/11/fig2_161038.jpg

/wp-content/uploads/2012/11/fig3_161045.jpg

Click Finish.

Create Process

Right click on Processes under Process Modeling node and select New Process.

/wp-content/uploads/2012/11/fig4_161046.jpg

/wp-content/uploads/2012/11/fig5_161047.jpg

Click Next Button

/wp-content/uploads/2012/11/fig6_161054.jpg

Click on Finish button.

Create Pool

Create the pool such that the final process will look as shown in the below figure:

/wp-content/uploads/2012/11/fig7_161055.jpg

Here I am going to explain two scenarios of using the Intermediate Timer

In Scenario one, I have used the Embedded Sub-Process.  In the Sub-Process I have two Human Activities and one Intermediate Timer between the two Human Activities.

When the process starts the human activity “Human 0” will be in the active state. The task will be visible in the UWL for the assigned user.  When the user claims the task from the UWL and completes the task then the active state will be at Intermediate Timer “Time T1”.  We need to calculate the duration of the “Human 0” using start activation time and the completion time.  We can get it from BPM tables but it is a complex job. The other way is get the time when the task is activated or completed by using the input mapping, output mapping and expression.  Once the time is captured the Intermediate Timer is set such that wait period will be (Total duration – duration calculated for Activity “Human 0”) before the Activity “Human 2” is activated.

Example:  The Human Activity “Human 2” should be activated after 5 minutes of activation of Human Activity “Human 0” assuming that the “Human 0” activity is completed within 5 min. after the process is started.  If the duration calculated of the Human Activity “Human 0” is 3 minutes then the Intermediate Timer should wait for a period of 2 minutes.

In Scenario two, I have used a parallel split with one connection to Human Activity and another to an Intermediate Timer. When the deadline of the task expires a Notification will be sent to the user.  If the user completes the Human Activity “T1” the Human Activity “T2” will not be activated until “T1 Timer” timer expires defined using the expression and vice versa.

Effective way of using the Intermediate Timer with Scenario One

Create a webdynpro component with two three UI elements which shows the start time of activation, end time and the duration.

/wp-content/uploads/2012/11/fig8_161056.jpg

Creation of Webdynpro Component (“TimeDurationComp”)

/wp-content/uploads/2012/11/fig9_161057.jpg

/wp-content/uploads/2012/11/fig10_161058.jpg

/wp-content/uploads/2012/11/fig11_161068.jpg/wp-content/uploads/2012/11/fig12_161069.jpg

public void Confirm( )  {

    //@@begin Confirm()

        wdThis.wdFireEventConfirm();

    //@@end

  }

/wp-content/uploads/2012/11/fig13_161071.jpg

/wp-content/uploads/2012/11/fig14_161337.jpg

/wp-content/uploads/2012/11/fig15_161338.jpg

/wp-content/uploads/2012/11/fig16_161340.jpg

/wp-content/uploads/2012/11/fig17_161341.jpg

public void onActionConfirm(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

    //@@begin onActionConfirm(ServerEvent)

         wdThis.wdGetTimeDurationCompController().Confirm();

  //@@end

  }

Add “TimeDurationComp” to the public part

/wp-content/uploads/2012/11/fig18_161345.jpg

/wp-content/uploads/2012/11/fig19_161346.jpg

Creation of Task.

Navigate to the Process development perspective.

Under the Tasks node of the Process Modeling create a new task “DateStr” with component “TimeDurationComp”

/wp-content/uploads/2012/11/fig20_161347.jpg

Creation of the Context for the Process

Expand the tree of the DC “ime” and drage the Context from the TimeDurationComp under DataTypes on to the Process diagram as shown in the below diagram.

/wp-content/uploads/2012/11/fig21_161348.jpg

/wp-content/uploads/2012/11/fig22_161349.jpg

Select the Human Activity “Human 0”.Click on properties. Select the task properties  and assign the task “DateStr”.

/wp-content/uploads/2012/11/fig23_161350.jpg

Select the Input Mapping properties and create a function as shown in the above diagram.  Edit the function and write an express as “replace(substring(string(current-dateTime()),0,19),”T”,” ”)”.  The current date time is converted to string first and then the first 19 characters are taken into account and then the letter “T”  is replaced with blank space.

The current-dateTime() will return “2012-10-26T11:24:56.893+05:30” which is in the format “YYYY-MM-DDThh:mm:ss.SSS+GMT”.  To calculate time the format should be in “YYYY-MM-DD hh:mm:ss” .

/wp-content/uploads/2012/11/fig24_161351.jpg

Similarly calculate the endtime by clicking on the Output Mapping properties and create the function with expression as “replace(substring(string(current-dateTime()),0,19),”T”,” ”)” as shown in the below figure.

/wp-content/uploads/2012/11/fig25_161352.jpg

Using the EndTime and StartTime attribute we have the Activation Time and Completion time for the Human Activity “Human 0” to calculate the duration of “Human 0” activity.  Assuming that the task “Human 0”will be completed before 5 min., the “Human 2” activity should be in ready state only after 5 min of activation of Human Activity “Human 0”.  So the Timer should be set to “300 – (EndTime -StartTime)”.  Since the timer is triggered in millisecond we have to multiply it by 1000 as shown in the blow diagram.

/wp-content/uploads/2012/11/fig26_161353.jpg

/wp-content/uploads/2012/11/fig27_161357.jpg

Select the Human Activity “Human 2” and assign the task “DateStr” task to show the start time, end time and duration of the activity “Human 0” as shown in the below diagram.

/wp-content/uploads/2012/11/fig28_161358.jpg

Select the Input Mapping Properties and complete the mapping as shown in the below figure.

/wp-content/uploads/2012/11/fig29_161359.jpg

Create a function “GetDurationTime” from the EBJ to calculate the duration as shown in the below figure.

/wp-content/uploads/2012/11/fig30_161360.jpg

Code in the EJB

package com.adi.ebj;

import java.util.Date;

import java.text.SimpleDateFormat;

import javax.ejb.Stateless;

import javax.xml.namespace.QName;

import com.sap.glx.sdo.api.SdoRenamingHelper;

import commonj.sdo.DataObject;

import commonj.sdo.Type;

/**

* Session Bean implementation class ConcatFunction

*/

@Stateless

public class ConcatFunction implements ConcatFunctionLocal {

private static final String NAMESPACE_FUNCTION_PARAMETER = “test.sap.com/sampleprocess”;

       private static final String PARAMETER1 = “parameter1”;

       private static final String PARAMETER2 = “parameter2”;

       private static final String RESULT = “result”;

       private static final String NAME_PROPERTY_INPUT_PARAMETER1 = SdoRenamingHelper.renameXsdElementToSdoProperty(new QName(NAMESPACE_FUNCTION_PARAMETER, PARAMETER1), false);

       private static final String NAME_PROPERTY_INPUT_PARAMETER2 = SdoRenamingHelper.renameXsdElementToSdoProperty(new QName(NAMESPACE_FUNCTION_PARAMETER, PARAMETER2), false);

       private static final String NAME_PROPERTY_OUTPUT_RESULT = SdoRenamingHelper.renameXsdElementToSdoProperty(new QName(NAMESPACE_FUNCTION_PARAMETER, RESULT), false);

public DataObject invokeSdo(DataObject inputDO, InvocationContext invocationContext) {

Type typeInput = inputDO.getType();

       String parameter1 = inputDO.getString(typeInput

                           .getProperty(NAME_PROPERTY_INPUT_PARAMETER1));

       String parameter2 = inputDO.getString(typeInput

                           .getProperty(NAME_PROPERTY_INPUT_PARAMETER2));

       int timeOut = 2;

       try

       {

              if(parameter1.equals(“T1”))

              {

                     timeOut=3;

              }     

              else if(parameter1.equals(“T2”))

              {

                     timeOut=2;

              }     

              else

              {

              try

              {

               SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

                Date sdate = (Date)sdf.parse(parameter1); // it should be java.util.date

                Date edate = (Date)sdf.parse(parameter2);

                timeOut  = (int)((edate.getTime() – sdate.getTime())/1000);

              }

              catch(Exception e1)

              {

                     timeOut=4;

              }

}

       }            

       catch(Exception e)

       {

              timeOut = 4;

       }

       DataObject outputDO = invocationContext.createOutputDataObject();

                     outputDO.setInt(outputDO.getType().getProperty(NAME_PROPERTY_OUTPUT_RESULT), timeOut);

       return outputDO;

       }

// Default constructor.

       public ConcatFunction() {

              // TODO Auto-generated constructor stub

       }

Effective way of using the Intermediate Timer with Scenario Two

/wp-content/uploads/2012/11/fig31_161465.jpg

Design the Scenario two as shown in the above figure.  Here there is no need to calculate the Time duration of the activation and completion of the task.  Here place an Intermediate time parallel to the task and assign the time in millisecond using the expression.  If the task is not completed with the specified time, check the checkbox “Completion deadline” and then we need to send a remainder mail to the user using the notification activity.

/wp-content/uploads/2012/11/fig32_161467.jpg

Edit the expression under “Completion Deadline” as add-minutes-todateTime(current-dateTime(),GetDurationTime(“T1”,” “)) and check the check box “Raise critical exception when deadline is reached.”  The function GetDurationTime will return 4 if it “T1” else it will return 3 if it is “T2”.

/wp-content/uploads/2012/11/fig33_161481.jpg

Add the Boundary event as “CompletionDeadlineIsCriticalException”

/wp-content/uploads/2012/11/fig34_161486.jpg

Set the mailer properties under notification as shown in the below diagram.

/wp-content/uploads/2012/11/fig35_161487.jpg

Set the Intermediate Timer “T1 Timer” as shown in the below figure.

/wp-content/uploads/2012/11/fig36_194608.jpg

/wp-content/uploads/2012/11/fig37_194642.jpg

/wp-content/uploads/2012/11/fig38_194643.jpg

Assign the process to the end users “User_Test_Adi_B, User_Test_Adi_A” using the expression as getPrincipals(tokenizer(USER.PRIVATE_DATASOURCE.un :User_Test_Adi_A, USER.PRIVATE_DATASOURCE.un: User_Test_Adi_B),”,”).

The task will be shown in UWL for both users but once a particular user claims the task, that particular task will be vanished from other users.

/wp-content/uploads/2012/11/fig39_194644.jpg

Steps to start the process

Log on to NWA in portal and then navigate to Configuration Management –> Process and Tasks –> Process Repository

From the List of Components table select the ime(demo.sap.ime.bpm.com)

From the Details of Component ime(demo.sap.ime.bpm.com) table select the TimerFunctionality of type Process Definition and click on the “Strat Process” button,  will open an window with “BPM Process Startup: Process” and then click on “start process” button.

The process flow diagram looks as shown below.  By double clicking the lens icon the embedded sub-process will be visible in a new window.

/wp-content/uploads/2012/11/fig40_194648.jpg

Logon to the portal with user id “User_Test_Adi_A” and click on the task “DateStr”.  You will find the activation time of this task as shown in the below figure.  From the process instance history you can find out the activation time as shown in the below diagrams

/wp-content/uploads/2012/11/fig41_194649.jpg

Click on the confirm button and view the process flow diagram.

/wp-content/uploads/2012/11/fig42_194650.jpg

/wp-content/uploads/2012/11/fig44_194658.jpg

Once the timer event is completed as per the calculated duration using the EJB the Human Activity “Human 2” will be in ready state.  The task will be visible in UWL for  user “User_Test_Adi_A” and “User_Test_Adi_B”.  Log on to the portal with user “User_Test_Adi_A” and click on the task “DateStr”.  Now the activation time, completion time and duration of Human Activity “Human 0” will be displayed.

/wp-content/uploads/2012/11/fig45_194659.jpg

Navigate to “Operation Management” –> Process and Tasks –>Manage Process

Select the process Instance name “TimerFunctionality” and click on “History” tab to view the history

/wp-content/uploads/2012/11/fig46_194660.jpg

The above process Instance figure will explain the history in details.

For Scenario Two.

In this Scenario we can see form the process flow diagram that the Human Task “T1” and the Intermediate Timer “T1 Timer” are in ready state.  If the task “T1” is completed first the Human Task “T2” will not be in ready state unless Intermediate Timer “T1 Timer” is completed and vice versa.

/wp-content/uploads/2012/11/fig47_194661.jpg

/wp-content/uploads/2012/11/fig48_194662.jpg

Even though the task “T1” is completed, the Intermediate Timer “T1 Timer” will be in ready state until the Intermediate Timer is completed.

/wp-content/uploads/2012/11/fig49_194666.jpg

The Timer “T1 Timer” will be in completed state after 3 minutes from its activation state.  Then Timer “T2 Timer” and Human Activity “T2” will be in ready state.

/wp-content/uploads/2012/11/fig50_194667.jpg

/wp-content/uploads/2012/11/fig51_194668.jpg

Once the task “T2” is completed and Timer “T2 Timer” is in completed state the process will end.

Navigate to “Operation Management” –> Process and Tasks –> Manage Process
Select the process Instance name “TimerFunctionality” and click on “History” tab to view the history

/wp-content/uploads/2012/11/fig52_194669.jpg

For Scenario Two (b)


In the design view of the process diagram click on the properties of human activity “T1” and instead of default task add a new task “RBUResource”.

If the default task is not changed, at run time when the critical exception event is raised the task is not visible in the UWL list of the user.

Make sure that Completion deadline is checked and make sure that the completion Deadline expression is written as shown in the below figure.

/wp-content/uploads/2012/11/fig53_194670.jpg

/wp-content/uploads/2012/11/fig54_194671.jpg

Deploy the DC and run the application.

Navigate to “Operation Management” –> Process and Tasks –> Manage Process
Select the process Instance name “TimerFunctionality” and click on “History” tab to view the history

/wp-content/uploads/2012/11/fig55_194678.jpg

In the above diagram the Intermediate Timer “T1 Timer” is completed but the task “T1” is not completed. A mail is send to the user using the notification email.  Once the user completes the task the task “T2” will be in ready state.

References


1.    http://www.sdn.sap.com/

2.    http://www.sdn.sap.com/irj/bpx/bpm

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply