Using XPath to find a specific node in a secondary datasource - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using XPath to find a specific node in a secondary datasource

Last post 12-07-2010 08:53 AM by Talvalin. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-03-2010 09:44 AM

    Using XPath to find a specific node in a secondary datasource

    Hello!

    Background first: I've got a form that is receiving data via a WCF webservice and is called GetSitesByCompanyId. The data is run on load (with a hardcoded company id for testing) and used to populate a dropdown box of Site Names. What I'm trying to do is to use code to populate details for the site when a selection is made from the dropdown. I can match the site name with a site id (although this involved the possibly dodgy method of creating a dictionary of site name to site id and populating said dictionary on form load), but I cannot seem to formulate an XPath query that will find the appropriate details in the result set for the given site id.

     Here's the code that I have. Any help would be greatly appreciated! If nothing else, a method for shortening the absolute paths I'm using would be good. :)

    /////////////////////////////

    // Set the site detail fields

    DataSource dsSites = this.DataSources["GetSitesByCompanyId"];XPathNavigator xnSites = dsSites.CreateNavigator();

     

    XPathNavigator addressLine1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SiteDetails/my:group4/my:AddressLine1", ns);

    XPathNavigator addressLineResult = xnSites.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetSitesByCompanyIdResponse/tns:GetSitesByCompanyIdResult/q1:Site/q1:AddressLine1[/dfs:myFields/dfs:dataFields/tns:GetSitesByCompanyIdResponse/tns:GetSitesByCompanyIdResult/q1:Site/q1:SiteId=\"" + siteId.ToString() + "\"])", ns);

    Filed under: , ,
  • 12-03-2010 09:54 AM In reply to

    Re: Using XPath to find a specific node in a secondary datasource

    Hi -- this can be done in code, but ... why? I mean, you could use rules for this. Rules would go on the field that the drop down is bound to, and you could select the field from your main data source as the target and the field you want from your secondary data source as the value. I must be missing a step in your description of your problem that would require code?

    Hilary Stoupa

  • 12-04-2010 04:28 AM In reply to

    Re: Using XPath to find a specific node in a secondary datasource

    From what I've read on the net, this can be achieved using rules and filters but I'm using a browser-enabled form so filters won't work right? I appreciate that I may not have a complete understanding of this problem as I'm very new to Infopath. The other problem I've encountered is that I can use rules to populate my site details, but I can only ever seem to populate details that correspond to the first site in the dropdown. Even if I choose a different site first, I only ever see the details for the first site. As a result of this, I've been trying to do this using code instead, but I'm encountering different problems now. If this can be achieved without code, then I'd love to do so. :)
  • 12-04-2010 08:54 AM In reply to

    Re: Using XPath to find a specific node in a secondary datasource

    There are areas in browser forms where you can't use filters, but you should be able to use them in the value formula of a rule just fine.

    Most likely the reason your formula is not working is that it should be:

    /dfs:myFields/dfs:dataFields/tns:GetSitesByCompanyIdResponse/tns:GetSitesByCompanyIdResult/q1:Site/q1:AddressLine1[../q1:SiteId = siteId]

    not that much longer version you have.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-07-2010 08:53 AM In reply to

    Re: Using XPath to find a specific node in a secondary datasource

    Thank you for your responses. I've since had to abandon this plan and have created another topic regarding the filtering of Sharepoint external lists here: http://www.infopathdev.com/forums/t/17791.aspx
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.