Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

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.

Provide name for the process DC.

Click Finish.

Create Process

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

Click Next Button

Click on Finish button.

Create Pool

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

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.

Creation of Webdynpro Component (“TimeDurationComp”)

public void Confirm( )  {

    //@@begin Confirm()

        wdThis.wdFireEventConfirm();

    //@@end

  }

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

  {

    //@@begin onActionConfirm(ServerEvent)

         wdThis.wdGetTimeDurationCompController().Confirm();

  //@@end

  }

Add “TimeDurationComp” to the public part

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”

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.

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

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” .

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.

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.

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.

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

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

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

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.

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”.

Add the Boundary event as “CompletionDeadlineIsCriticalException”

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

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

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.

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.

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

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


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.

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


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

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.

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

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.

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

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.

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

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

Labels in this area