Get current time in Sharepoint Designer workflow - SharePoint Development & Administration + InfoPath

Saturday, March 21, 2009

Get current time in Sharepoint Designer workflow

Get the current time in a standard SharePoint Designer workflow and assign to a workflow variable
I was having trouble getting the current time in a SharePoint Designer workflow when testing against a date/time field of the current item. I noticed that when testing if the date was greater than [today] which is the only option to test against the current date, the time was ignored as [today] returned 12:00 AM as the time.
To be a little more specific, I needed separate actions performed on the current item if the item's creation date/time + 4hrs was greater or less than the current time. In other words, the condition test was if it was created less than or greater than 4 hours ago.

Being unable to select a [now] option to test against the current time, I was getting unexpected results.

My solution (a little clunky, but works) to get the current time was to modify/update a temporary list item (update any filed with any value), wait a minute and then store the modification date in a workflow variable. I found that updating an item and getting the modification date was more efficient than creating a new item and getting the creation date.

I also found that if there is not a pause after creating/modifying the temporary list item an error often occured in the workflow when trying to get the modification date of the recently updated list item, as the modification had not yet registered correctly in the list. Setting a pause for the minimum (1 minute) ensures that when the date is retreived, the list item is ready.
Share this article:
Stumble This Delicious
Delicious
submit to reddit
Facebook
MySpace
MySpace

2 comments:

Jeroen Ritmeijer said...

Very creative solution.

You may want to consider just embedding C# or vb.net code directly in your SharePoint Designer workflow using the Workflow Power Pack (http://www.muhimbi.com/blog/2009/12/embed-c-or-vb-code-directly-in.html).

I have done some work on this tool and it makes life the workflow developer so much easier.

DanielS said...

Thanks Jeroen

Post a Comment