Infopath Repeating Table for Sharepoint 2010 - xpath to compare several date fields and identify the latest one - InfoPath Dev
in

InfoPath Dev

Infopath Repeating Table for Sharepoint 2010 - xpath to compare several date fields and identify the latest one

Last post 02-02-2015 08:27 AM by AndreasEG. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-07-2015 04:04 AM

    Infopath Repeating Table for Sharepoint 2010 - xpath to compare several date fields and identify the latest one

    Hi,

    I have a repeated table with 6 date fields in a record and need to determine the latest of these per record.

    For numeric fields this is simple by using the MAX function in default value of the target field: xdMath:Max(../my:dt1 | ../my:dt2 | ../my:dt3 | ../my:dt4 | ../my:dt5 | ../my:dt6)

    Unfortunately, MAX does not work for date fields.

    Any idea how this can be done efficiently?

    I have developed an approach which however seems to me very complicated and I doubt it cannot be done easier:

    The approach is to do pairwise comparisons of dates:
    dt12max=maximum(dt1,dt2)
    dt34max=maximum(dt3,dt4)
    dt56max=maximum(dt5,dt6)
    dt1234max=maximum(dt12,dt34)
    dtdt123456max=maximum(dt1234,dt56)

    ... where each comparison would look like the statement below - which is kind of a if/then statement using the string-compare function for the actual comparison:
    concat(substring(string(../my:dt2), 1, number(0 > (msxsl:string-compare(../my:dt1, ../my:dt2))) * string-length(string(../my:dt2))), substring(string(../my:dt1), 1, number(not(0 > (msxsl:string-compare(../my:dt1, ../my:dt2)))) * string-length(string(../my:dt1))))

    This approach works but needs 5 help variables and a long xpath statement in each variables default value.

    I attach the xsn and the xml file. In the third repeated table (group4) DTMax is the target field for the comparison of dt1 to dt6. DTMax12 is the target field for my own complex approach for comparing dates dt1 and dt2.


    Is there a simpler way to perform multiple dates to determine the latest one?

    Regards
    Andreas

  • 01-07-2015 07:15 AM In reply to

    Re: Infopath Repeating Table for Sharepoint 2010 - xpath to compare several date fields and identify the latest one

    What if you took the same approach you would take for a numeric field, but use a translate function to strip the non-numeric chars out of the date? So 2015-01-15 becomes 20150115 and 2014-12-13 becomes 20141213?

    Hilary Stoupa

  • 02-02-2015 08:27 AM In reply to

    Re: Infopath Repeating Table for Sharepoint 2010 - xpath to compare several date fields and identify the latest one

    Hi Hilary, great - it worked. I just had to insert "-" into the string again so that it is accepted as date format. Regards Andreas

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.