Stumbling Through

Join me as I stumble, bumble and fumble my way through some new developer technologies. We'll laugh, we'll cry, there may be a mouse tossed through a monitor, but in the end we will all hopefully learn something.
in

Stumbling Through: K2 Blackpearl (Automatic Workflows Part II)

We left off previously with a workflow that can automatically assign itself to an appropriate user after a set amount of time passes, effectively simulating a reoccurring workflow.  There was one major weakness, however, and that is that the time used to determine when to escalate the activity is based on the number of days/hours/minutes since the activity was last completed.  While this may be due to the design of the workflow, it lends itself to a good topic for a blog, and that is manually manipulating the code generated by blackpearl workflow items.  What I want to do is modify the escalation rule that we defined previously to execute every five minutes to instead escalate at the top of the hour every hour, regardless of when the last process was closed by the user.  Using our current rules, if the user closed the activity at 11:05am, it would escalate again at 12:05pm (if we made it escalate every hour).  What I want it to do, is escalate at 12:00 no matter when during the 11 hour it was closed.  Lets take a closer look at how we will accomplish this by opening the workflow we created in the previous post and opening its 'Activity Escalations' dialog:

image

In this dialog, we get the option to select an escalation and view its rule code:

image

Select this option, and we are presented with the Windows Workflow representation of this escalation rule:

image

We can double click the one code item in this workflow to bring us to its source code:

image

Right away, we can see the logic that sets the K2 Escalation rule equal to whatever values were entered into the escalation configuration dialog (The K2.Configuration items).  Instead of pulling the values from the configuration, we'll calculate the values based on our business rule, that is, since it should always escalate at the top of the hour, we will set 'EscalateMinutes' equal to however many minutes are left in the current hour:

 

private void EscalateAfterRule_ExecuteCode(object sender, EventArgs e)
{
    int EscalateDays = 0;
    int EscalateHours = 0;
    int EscalateMinutes = 60 - DateTime.Now.Minute;
    int EscalateSeconds = 0;
    int EscalateRepeatedTimes = K2.Configuration.EscalateRepeatedTimes;

    K2.SetEscalationRule(EscalateDays, EscalateHours, EscalateMinutes, EscalateSeconds, EscalateRepeatedTimes);
}

 

Save the changes and deploy the workflow, start it up and make sure it appears in the service account's task list:

image

Now we'll have to wait until the top of the hour to see if it automatically escalates to my task list.

*** Time Passes ***

image

Bam!  There it is in my task list, though oddly enough, the 'Event Start Date' is still the same as the original event start date.  I assumed it would update to the time at the top of the hour when it was redirected, but that is a minor issue considering it actually arrived at the top of the hour.

Posted: Nov 30 2007, 03:39 PM by tbyrne | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)