Xpath statement referencing 2 different data sources - InfoPath Dev
in

InfoPath Dev

Xpath statement referencing 2 different data sources

Last post 12-07-2008 10:35 AM by Greg S. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-05-2008 05:29 PM

    • Greg S
    • Not Ranked
    • Joined on 10-15-2006
    • Posts 9

    Xpath statement referencing 2 different data sources

    Without doing code behind (i.e. just using standard InfoPath rules), is it possible to set a field's value based on an Xpath expression where that Xpath expression contains a reference to another field? 

    For example this xpath statement works for setting a field's value in a rule, but the "where" clause is hard-coded to 123:

    xdXDocument:GetDOM("Data connection 1")/dfs:myFields/dfs:dataFields/dfs:myRecord[@ID = "123"]/@Title

    This obtains the correct @Title value for the record where the @ID attribute is "123", but I need to replace "123" with some value in another field on the form that is bound to a different data source.

    Is this possible without doing code behind and doing multiple queries against the different data sources?

  • 12-05-2008 06:52 PM In reply to

    Re: Xpath statement referencing 2 different data sources

    Generally you should be able to accomplish it with something like this:

    xdXDocument:GetDOM("Data connection 1")/dfs:myFields/dfs:dataFields/dfs:myRecord[@ID = xdXDocument:GetDOM("Data connection 2")/path/to/other/field]/@Title

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-06-2008 10:24 AM In reply to

    • Greg S
    • Not Ranked
    • Joined on 10-15-2006
    • Posts 9

    Re: Xpath statement referencing 2 different data sources

    Jimmy:

    Generally you should be able to accomplish it with something like this:

    xdXDocument:GetDOM("Data connection 1")/dfs:myFields/dfs:dataFields/dfs:myRecord[@ID = xdXDocument:GetDOM("Data connection 2")/path/to/other/field]/@Title

    I should add one other caveat, the 2nd data connection is the Main data source, and I can't get xdXDocument:GetDOM to work against the Main data source.  I've tried xdXDocument:GetDOM("") and xdXDocument:GetDOM ("Main").  I if just use the path the main datasource like below, nothing is returned.

    xdXDocument:GetDOM("connection 1")/dfs:myFields/dfs:dataFields/dfs:myRecord[@ID = /my:myFields/my:mainID]/@Title 

    "/my:myFields/my:mainID" is the xpath to the field acting as my "where" clause.  If I use that path by itself in another "set value" rule it does return a value.  I just can't get it to work in combination with the GetDom attempt above.

    Right now I'm using a work-around in code-behind, but it's a good academic exercise to know if this can be done.

    Thanks.

  • 12-06-2008 10:35 AM In reply to

    Re: Xpath statement referencing 2 different data sources

    For the main data source, xdXDocument:get-DOM() should do the trick:

    xdXDocument:GetDOM("connection 1")/dfs:myFields/dfs:dataFields/dfs:myRecord[@ID = xdXDocument:get-DOM()/my:myFields/my:mainID]/@Title 

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-07-2008 10:35 AM In reply to

    • Greg S
    • Not Ranked
    • Joined on 10-15-2006
    • Posts 9

    Re: Xpath statement referencing 2 different data sources

    Thank you!  I didn't know about get-DOM() -- and so easy to avoid notice when I'm used to using GetDOM("xx").  Works like a charm.

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