6

Question

How can I check for an empty date condition in a SharePoint Designer Workflow?

Background

I have a list called "Project" with multiple date fields. I have a calendar called "Project Scheduling" where I want to copy those dates. For every pair of two dates (such as "Construction Start"/"Construction End" and "Design Start"/"Design End") for a single "Project" listitem I want to create one list item in the calendar.

I do this by creating a workflow that triggers on add/change and will push the dates to the calendar if both dates in the pair have a value. To check for null dates I have to first store the string values of the dates in workflow variables because you cannot use the "is empty" condition with a date field. However, when I try to check for "is empty" on the date string values the string returns as not empty and it tries to execute my code for creating the item in the "Project Scheduling" calendar. For some reason that fails even though the string is not empty. I would assume that it would succeed seeing as how there was a value in the date string.

7

I tried logging the date string values before executing the creation of the listitem in the "Project Scheduling" calendar but the workflow would error without logging. Then I removed the listitem creation part and the logging worked. It was there that I noticed that the date values were set to 1/1/0001 12:00:00 AM.

Workflow History Date Values

I found the same problem on Cliff Chaney's Blog and he provided the solution of:

  1. Converting the date to a short date
  2. Storing the date in a string workflow variable
  3. Comparing the string workflow variable to "1/1/0001"
  • 6
    All because stupid SharePoint doesn't just have an option to say "If it's empty" – Christine Jan 4 '17 at 20:48
3

Since a date field defaults to 1/1/0001 12:00:00 AM, to check for null dates set the workflow to check to see if the specified field date is less than the Created date. If the date field is less than the Created date then you know the field is empty.

  • 4
    ...which excludes anyone in the - very likely - scenario of wanting to create an item that refers to an earlier date. – underscore_d Oct 19 '15 at 14:07
0

Date fields are never truly empty, so the option doesn't exist. An "empty" date field is actually set to 1/1/0001.

So for your specific project, forget the whole "storing the string values of the dates" thing, that won't work. Instead, set up the workflow to perform the action if both Date fields are greater than 1/1/0001.

0

I've also found that creating a Local Variable called BlankDate of type Date/Time works as a way to CHECK for an empty date.

Unfortunately, it doesn't work for SETTING a field to null.

For setting a "null" date, the best I could do was creating a Local Variable called NullDate of type Date/Time and setting it to 1/1/1900 12:00:00 AM.

Then that means I have to check for BlankDate or NullDate.

0

You can just check to see if the field is less than 1/1/2001 - that works for checking to see if the field hasn't been populated. Even though it prints out on a log as 1/1/0001 - checking to see if equal to that value doesn't work. Also less than 1/1/2000 doesn't work either - but less than 1/1/2001 worked for me on SP 2013 (2010 workflow).

protected by Mohamed El-Qassas MVP Apr 27 '18 at 21:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.