XPATH Code Help. Pull from two Data Sources - InfoPath Dev
in

InfoPath Dev

XPATH Code Help. Pull from two Data Sources

Last post 02-11-2014 11:09 PM by RaYvA. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 01-22-2014 08:39 AM

    XPATH Code Help. Pull from two Data Sources

    Hi,

    I'm trying to pull from two data sources into one field based on some conditions:

    xdXDocument:GetDOM("IMA Tasks Team 1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()] or xdXDocument:GetDOM("BSD Second Task List")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()] 

    I'm using OR in my syntax does not seem to recognize both statements.

    Please Help 

    Filed under:
  • 02-11-2014 11:09 PM In reply to

    • RaYvA
    • Top 100 Contributor
    • Joined on 05-08-2013
    • Melbourne, Australia
    • Posts 86

    Re: XPATH Code Help. Pull from two Data Sources

    Hi, you have to use some logic called "Becker's method", attributed to Oliver Becker, which looks like this:

    concat(
      substring($s1, 1, number($condition)      * string-length($s1)),
      substring($s2, 1, number(not($condition)) * string-length($s2))
    )

    Which then has to be wrapped into the familiar 'double eval' expression in Infopath for it to work.

    Here is an expression I've used previously that ONLY works if one of the input expressions IS Blank (IT WILL NOT WORK IF BOTH EXPRESSIONS CONTAIN DATA!):

    xdMath:Eval(xdMath:Eval(../my:FirstArgument, 'concat(substring(../my:FirstArgument, 1, ../my:FirstArgument * string-length(../my:FirstArgument)), substring(../my:SecondArgument, 1, (string-length(../my:SecondArgument) > 1) * string-length(../my:SecondArgument)))'), "..")

    So, assuming your field expressions are correct, substituting FirstArgument and SecondArgument with your field expressions and your expression should look something like:

    xdMath:Eval(xdMath:Eval(xdXDocument:GetDOM("IMA Tasks Team 1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()], 'concat(substring(xdXDocument:GetDOM("IMA Tasks Team 1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()], 1, xdXDocument:GetDOM("IMA Tasks Team 1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()] * string-length(xdXDocument:GetDOM("IMA Tasks Team 1")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()])), substring(xdXDocument:GetDOM("BSD Second Task List")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()], 1, (string-length(xdXDocument:GetDOM("BSD Second Task List")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()]) > 1) * string-length(xdXDocument:GetDOM("BSD Second Task List")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[../d:Title = current()])))'), "..")

    Maybe my XPath is wrong, but I hope you understand what is supposed to happen.  If your first field expression returns an ID it will be returned, if your second field expression returns and ID it will be returned.

    Hope this helps

    Cheers

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