Escalations -

  • 14 January 2008
  • 1 reply
  • 4 views

Badge +8

We use escalations in our workflow process. The intention was to calculate a due date based on the start date + the activity expected duration, then add 7 days before performing the escalation action (email). repeat every 7 days up to 10 times until the activity has been completed.


Each client activity has an escalation rule that calls an 'Escalate' function in a code module. This is the function:


Public Shared Sub Escalate (K2 As EscalationRuleContext)
  Dim ExpectedDuration As Long  'expected duration of the calling activity - expressed in minutes
  Dim StartDateTime As DateTime  'StartDateTime of the calling activity
  Dim EscalationDateTime As DateTime 'will be start datetime plus expected duration plus 7 days
  
'Get start datetime of activity, add expected duration, then add 1 week. This is datetime of first escalation
  
  StartDateTime = CType(K2.ActivityInstance.StartDate.ToString, Date)
  ExpectedDuration = CType(k2.ActivityInstance.ExpectedDuration.ToString, Long)
  EscalationDateTime = DateAdd(DateInterval.Minute, ExpectedDuration, StartDateTime)
  EscalationDateTime = DateAdd(DateInterval.Day, 7, EscalationDateTime)


  'first escalation is on EscalationDateTime; 10 more 7 days apart
  
  K2.SetEscalationRule(EscalationDateTime, 7, 0, 0, 0, 10)
End Sub


And each activity has an escalation action - a simple email function.


So now we are having problems with escalation notices being sent out after an activity was completed, and even after the workflow was completed. The first one went like this:




  • Step started on 12/28/07 7:27AM. 2 days expected duration, completed 1/7/08 8:39 am,  a bit more than 25 hours after the first escalation time arrived.


  • an escalation email was sent on this task on 1/13/08 7:27AM, more than 6 days after the activity was completed

And the second one like this:




  • last step of workflow had 3 activity instances. They started on 12/27/07 2:03 pm, expected duration of 3 days, so the due date was 12/30/07 2:03 pm.


  • the 3 instances were completed on 12/27/07 2:05 pm, 12/27/07 2:06 pm, and 1/7/08 3:48pm.


  • All 3 folks received an email sent on 1/13/08 1:03 pm.


  • the workflow completed on 1/7/08 3:48pm.


  • This last activity executes a gotoActivity to a clean-up process - moving files to a completed folder, etc.

So what is going on? Why would the email get sent if the process was no longer active?


1 reply

Badge +8

I suppose I should change the email function for escalation to check for completion of the Activity Instance Destination before sending the emai.


 


Here is the existing code:


 


Public Shared Function Email(ByVal K2 As EscalationActionContext)


   Dim objMsg As New System.Web.Mail.MailMessage()


   Dim objAttachment As System.Web.Mail.MailAttachment


   Dim objSender As System.Web.Mail.SmtpMail


   Dim strFrom As String


   Dim strEmail As String


   Dim strSubject As String


   Dim strBody As String


   Dim oActDest As SourceCode.KO.ActivityInstanceDestination


   Dim strActivityName As String


 


   objSender.SmtpServer = SourceCode.K2Utilities.GeneralMod.GetDefaultSMTPServer()


   strFrom = K2.ProcessInstance.Originator.Email


 


   For Each oActDest In K2.ActivityInstance.Destinations


      If IsNothing(oActDest.User.Email) OrElse oActDest.User.Email.Trim().Length = 0 Then


         Throw New System.Exception("No Email Address was supplied for User:" & _


            oActDest.User.FQN & ", please rectify and try again.")


      End If


      strEmail = strEmail & oActDest.User.Email & ";"


   Next


   If IsNothing(strEmail) OrElse strEmail.Trim().Length = 0 Then


      Throw New System.Exception("No Email Address was supplied, please rectify" & _


         " and try again.")


   End If


 


   strActivityName = K2.ActivityInstance.Activity.Name.ToString  


 


   If strActivityName <> "" Then


      strSubject = "***** Late Notice for " & strActivityName & " *****"


   Else


      strSubject = "***** Late Notice *****"


   End If


 


   strBody = strBody & SourceCode.K2Utilities.XMLFieldMod.GetXMLValue _


       (K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value, _


       "my:myFields/my:MocEntryForm/my:MOCNumber")


   strBody = strBody & " "


   strBody = strBody & SourceCode.K2Utilities.XMLFieldMod.GetXMLValue _


      (K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value, _


      "my:myFields/my:MocEntryForm/my:Title")


   strBody = strBody & System.Environment.NewLine


   strBody = strBody & System.Environment.NewLine


   strBody = strBody & "This is a notification that the " & strActivityName & _


      " task assigned to you is overdue and has not been completed. Please" & _


      " complete this activity as soon as possible."


   strBody = strBody & System.Environment.NewLine


 


   objMsg.From = strFrom


   objMsg.To = strEmail


   objMsg.Subject = strSubject


   objMsg.Body = strBody


   objSender.Send(objMsg)


 


End Function


 


I guess I should change it to something like this:


 


Public Shared Function Email(ByVal K2 As EscalationActionContext)


   Dim objMsg As New System.Web.Mail.MailMessage()


   Dim objAttachment As System.Web.Mail.MailAttachment


   Dim objSender As System.Web.Mail.SmtpMail


   Dim strFrom As String


   Dim strEmail As String


   Dim strSubject As String


   Dim strBody As String


   Dim oActDest As SourceCode.KO.ActivityInstanceDestination


   Dim strActivityName As String


 


   objSender.SmtpServer = SourceCode.K2Utilities.GeneralMod.GetDefaultSMTPServer()


   strFrom = K2.ProcessInstance.Originator.Email


 


   For Each oActDest In K2.ActivityInstance.Destinations


 


‘Check for completion of the activity instance destination before sending email


      If oActDest.Status <> SourceCode.KO.ActInstDestStatus.Completed Then        


 


         If IsNothing(oActDest.User.Email) _


            OrElse oActDest.User.Email.Trim().Length = 0 Then


            Throw New System.Exception("No Email Address was supplied for User:" _


               & oActDest.User.FQN & ", please rectify and try again.")


         End If


 


         strEmail = oActDest.User.Email


 


         If IsNothing(strEmail) OrElse strEmail.Trim().Length = 0 Then


            Throw New System.Exception("No Email Address was supplied, please " & _


               "rectify and try again.")


         Else


            strActivityName = K2.ActivityInstance.Activity.Name.ToString  


            If strActivityName <> "" Then


               strSubject = "***** Late Notice for " & strActivityName & " *****"


            Else


               strSubject = "***** Late Notice *****"


            End If


 


            strBody = strBody & SourceCode.K2Utilities.XMLFieldMod.GetXMLValue _


               (K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value, _


               "my:myFields/my:MocEntryForm/my:MOCNumber")


            strBody = strBody & " "


            strBody = strBody & SourceCode.K2Utilities.XMLFieldMod.GetXMLValue _


               (K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value, _


               "my:myFields/my:MocEntryForm/my:Title")


            strBody = strBody & System.Environment.NewLine


            strBody = strBody & System.Environment.NewLine


            strBody = strBody & "This is a notification that the " & strActivityName & _


               " task assigned to you is overdue and has not been completed. Please" & _


               " complete this activity as soon as possible."


            strBody = strBody & System.Environment.NewLine


 


            objMsg.From = strFrom


            objMsg.To = strEmail


            objMsg.Subject = strSubject


            objMsg.Body = strBody


            objSender.Send(objMsg)


         End If


      End If


   Next


End Function


 


Comments? Will this fix the problem?

Reply