marcwenger
marcwenger

Reputation: 439

XPath - is a date null

Using XPath, how do I figure out if a date or datetime field is null or blank?

I am using the concat method as a stand-in for the XPath if statement

concat(
substring(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd, 1, ../preceding-sibling::my:PerDiem[1]/my:perDiemEnd = "" * string-length(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd)),
substring(/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime, 1, not(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd = "") * string-length(/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime))
)

More info: In Infopath 2010, a repeating table has two date/time fields called perDiemStart and perDiemEnd. In the repeating table, the next perDiemStart is the previous perDiemEnd. This is easily done if the default value of perDiemStart is ../preceding-sibling::my:PerDiem[1]/my:perDiemEnd

But for the first perDiemStart (since a previous perDiemEnd does not exist, I suppose it would be null/blank). I want that first (blank) value to be a different: value of departureDateTime node

Node locations:

/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime

/my:ExpenseForm/my:PerDiemDetails/my:PerDiems/my:PerDiem/my:perDiemStart

/my:ExpenseForm/my:PerDiemDetails/my:PerDiems/my:PerDiem/my:perDiemEnd

Upvotes: 1

Views: 2351

Answers (2)

Mauritz Hansen
Mauritz Hansen

Reputation: 4774

To check if it is filled:

perDiemStart[text()]

To check if it is empty/null:

perDiemStart[not(text())]

Upvotes: 1

snibbets
snibbets

Reputation: 1145

Does this help? http://blogs.msdn.com/b/syamp/archive/2011/03/13/fim-2010-xpath-how-to-check-null-value-on-a-datetime-attribute.aspx

Basically they detect null dates by getting the set of dates after an old date (e.g. 1900-01-01) and then using 'not' to see which nodes would be excluded.

Upvotes: 0

Related Questions