Skip to main content

I am trying to create an outcome that compares the current date against a date specified in a form but I'm not sure how to get the current date for the comparison.  I was going to accomplish this the following way:


First Variable: Date Specified by Originator
Comparison Operator: <
Second Variable: Current Date (this is the one I need help with)

There are a few ways this can be done, but I think the easiest way is to create a process data field to store today's date.  You can set this value within code in a server event then compare this to the date passed in from the user in the line rules.


Attached is a screen shot of simple process I created to show this.


1. I created 2 process data fields.  'SomeUserEnteredDate' is what is passed in from the user.  'Today' is another Process Data Field (of Date datatype) that will store the current date.


2. In the 'Get Todays Date' Server event set the 'Today' process data field to the current date time with the following line of code:


            K2.ProcessInstance.DataFieldsn"Today"].Value = DateTime.Now;


3. In the line rules I then use logic like "SomeUserEnteredDate < Today" and "SomeUserEnteredDate >= Today"


 


 


17169i560F11ADF3ABA591.jpg

Can I use this: "K2.ProcessInstance.DataFields["Today"].Value = DateTime.Now" as part of a conditional statement or can it only be run in code?  I'm not sure the above will work because I need it to check the date more than once.  Basically, I have a task assigned to a user, and if the user doesn't complete the task before a specified date I want it to take a different route.


 I also have another similary workflow in which I want a notification sent out 14 days before a specified date.


Unfortunately that statement will only work within a Code block, not within the wizard field.


I'm not sure I understand why this example wouldn't work for your situation.  The reason I set the "Today" data field explicity within a Server event is to make it easy to reuse within line rules.  Attached is a screen shot of the two line rules I created in the previous example.  You'll see that within the actual line rules I am simply comparing the two process data field dates ('SomeUserEnteredDate' and 'Today').  The only thing different between these line rules is the comparison operator.


16314iA7D68C82A795B694.jpg

Ok, maybe I'm reading this wrong.  I assumed that if I set the current date in a Code Block that it would only run once, i.e. if the Block was executed today it would have today's date and if I wanted to view the data field tomorrow it would still contain today's date...is that correct?


I need "todays date" to be updated regularly so it can be compared against another parameter in the line rule.  For example, say I only had one outcome (today > entered date).  If it ran today (12/28/07) vs an entered date of 12/31/07 then it would be false and stay at the current step.  I want it to later update "today" and check against entered date again, and so on until today is greater than entered date, at which point it would continue to the next step.


You are correct in that the server event within this specific example will execute only once at the begining of the process.  If you need to check this date at certain points throughout the process you can simply copy the 'Get Todays Date' server event where needed.


I have attached an updated sample process definition.  In this new one notice that I call the 'Get Todays Date' after every client event.  This means that whenever a user finishes his/her task (i.e. client event) this server event runs and gets the current date.  The lines then implement the logic outline earlier in this thread.


Does this sound like it will meet the needs?


14795i4ACCB2E1F5A81332.jpg

Ok, let me be a little more specific about my process.  Below is a screenshot of the end of the Process.  Basically a form is filled out for a Manufacturing Work Request.  In the request a Duration is set.  The Implementation Action should generally conform to the duration.  What I would like to happen, is 14 days before the duration expires, I would like DefaultActivit1 to run (just sends a notification to manufacturing that the time is almost up).  So the problem is, its not a matter of running the getTodaysDate after every process because all of the comparison happens within only one process. 


It's entirely possible that I'm just going about this the wrong way so feel free to make any suggestions.


11307iF3E9D13AEE083557.jpg

So if I understand correctly, the entire purpose of DefaultActivity1 is to simply send an email reminder, however "Implementation Action" should still remain active.  Is this correct?


Assuming I now understand your need correctly then you will not need to do handle this via Line Rules.  What you will want to use is a K2 Activity Escalation.  If you are not familiar with escalations in K2 their entire purpose is to make sure things happen within a designated period(s) of time.  I highly recommend reading up on Escalations within the K2 User Guide ("K2 blackpearl] User Guide K2 for Visual Studio K2 Designer for Visual Studio K2 Escalations").  I think youi'll want to use an Activity Escalation.


Escalations are very powerful as you can have many attached to a single entity like an event.  For example, you may have one that fires at T-14 days to send the reminder email then another one that fires at T-0 to force this activity to expire. 


HTH.


Reply