Skip to main content
Lets say we have a process that has a 'date' datafield, e.g. a expiry date. The server needs to monitor the current date, and when the expiry date matches the current date, the event item must fire or the process must continue to the next event.

how would one force the server to only evaluate the condition once a day rather than constantly, in order to save cpu time? any suggestions would be welcomed.
There might be other ways of doing this but my suggestion is the following:

Use a "Goto" Escalation

You have a Process Datafield called "EscalationDate". In a server event, change the date as pleased

Sub Main(ByVal K2 As ServerEventContext)
Dim DateTime As DateTime = "2/20/2004 10:31:00 AM"
Console.WriteLine("The formatted time ----> " & DateTime)
K2.ProcessInstance.DataFields.Item("EscalationDate").Value = DateTime
K2.Synchronous = True
End Sub

Now configure a Goto Escalation to goto the next activity when the conditions are met:

Sub Main(Byval K2 as EscalationRuleContext)
Dim DateTime As DateTime = K2.ProcessInstance.DataFields.Item("EscalationDate").Value
Console.WriteLine("The Escalation Date Value --->" & K2.ProcessInstance.DataFields.Item("EscalationDate").Value)
K2.SetEscalationRule(DateTime)
End sub

There you go... 😃
A simpler way in which to 'delay' the starting of activity to a specific date/time (either hardcoded or stored in a process data variable), is to make use of the 'Start Rule' property of an activity. (No code required).

Cheers
Olaf
OK I'm setting a start rule for a server event as follows:

Dim ReturnDate as String
Dim CheckDate as DateTime

ReturnDate = K2.ProcessInstance.Datafileds("ReturnDate").Value
CheckDate = CDate(ReturnDate)
CheckDate = DateAdd(DateInterval.Day, 1, CheckDate)
Console.WriteLine("Check Date: " & CheckDate)
K2.SetStartRule(CheckDate)


The WriteLine proves that the correct date is being sent to the startrule.

The problem is that if ReturnDate is today or a date less than a month from today the process starts the day after the return date, (which is correct), but if ReturnDate is a date more than a month from today the process starts immediately. Where am I going wrong?
Please make sure that the date you pass in is in the correct format.

Dim DateTime As DateTime = "2/20/2004 10:31:00 AM"
Console.WriteLine("The formatted time ----> " & DateTime)
K2.ProcessInstance.DataFields.Item("EscalationDate").Value = DateTime

It's very important that you use the correct format. If there's no success, please include the date format and code in a reply so that I can test the code on my side. I will be glad to help you in this regard.
icon-quote.gifNeilM:

The problem is that if ReturnDate is today or a date less than a month from today the process starts the day after the return date, (which is correct), but if ReturnDate is a date more than a month from today the process starts immediately. Where am I going wrong?


You are doing nothing wrong 😃 This is a bug that has been identified with the start rule. It appears that as soon as you go beyond 21 days (or is it 25 days?), then the activity starts immediately.

This is currently being investigated by the labs team, but should be repaired for the upcoming service pack.

A workaround for this, is to put a second activity prior to this activity. In that manner you can specify 20 days in the first activity, and another 10 days in this activity to get a whole month. (Simply put a blank server event in the previous activity, which effectively does nothing).

Cheers
Olaf
Thanks Olaf. IIRC, the problem occurs with any date 23 days or more from now(). Your workaround won't work in this case though, as the return date can be any date in the future (up to a year or more from now) and I'm not going to add activities for every 20 days for the next 5 years 🙂.

I suspect the problem may occur because the date is actually stored as a string in the K2 log (processdata) db, and the conversion from that string to a date is not happening correctly. We'll just have to wait for the fix then...

Reply