Secondary Data Source - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Secondary Data Source

Last post 03-19-2007 11:39 AM by grhind. 23 replies.
Page 1 of 2 (24 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-24-2004 10:48 AM

    Secondary Data Source

    For some reason when I attempt to access a field that exists within my Secondary data source, I'm receiving back "nothing". The field is currently displaying on the form, but maybe I'm not using the right field name to access it. To get the field name I: drag the control onto the form, go into Data Validation, and select OnAfterChange and this will display code in VB.Net. I then take code from the top line which appears to represent the control.

    i.e my main data source looks like this:

    Dim myNode As IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/s0:SelectHardwareSoftwareRequestByIDResponse/s0:SelectHardwareSoftwareRequestByIDResult/ns1:DataSet1/ns1:dbo_udp_SelectHardwareSoftwareRequestByID/ns1:HardwareOrSoftware")

    and my secondary data source looks like this:

    Dim myNode As IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/ns4:SelectEmployeesWithHardwareSoftwareRequestResponse/ns4:SelectEmployeesWithHardwareSoftwareRequestResult/ns1:DataSet1/ns1:Table1/ns1:EmployeeID")

    My primary will return the node, but my secondary will return nothing, although it appears on the page and the data is in the control.
  • 11-26-2004 01:14 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59
    Two quick observations, both probably irrelevant :) :

    1. You have set the SelectionNamespace for the secondary, haven't you? (Otherwise, I think you would actually get an error)

    2. Which record/row in ns1:Table1 do you think this is pulling from? It'll be whatever the first one happens to be, I think.

    Also, just generally for this sort of stuff, I find using the debugger invaluable. In the Watch window, just try out your XPath queries etc. a bit at a time, e.g. start with:
    thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/ns4:SelectEmployeesWithHardwareSoftwareRequestResponse")

    and build up from there. You can see what's in the tree a bit at a time.
  • 11-26-2004 07:11 PM In reply to

    The most important thing here is that you are not accessing your secondary data source. In both cases you are accessing the main data source.

    To access the secondary data source you have to use:

    thisXDocument.GetDOM("MyDataSourceName").selectSingleNode("...");

    Greg Collins [InfoPath MVP]
  • 11-29-2004 05:39 AM In reply to

    Hey Greg,


    I just tried what you requested and received the following error...
    Run-time exception thrown : System.Runtime.InteropServices.COMException - Reference to undeclared namespace prefix: 'dfs'.


    This is my statement

    Dim myUserNode As IXMLDOMNode = thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").selectSingleNode("/dfs:myFields/dfs:dataFields/ns4:SelectEmployeesWithHardwareSoftwareRequestResponse/ns4:SelectEmployeesWithHardwareSoftwareRequestResult/ns1:DataSet1/ns1:Table1/ns1:EmployeeID")


    After further testing...
    When statement looks like this

    thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").selectSingleNode("EmployeeID")

    I get "nothing"
  • 11-29-2004 08:03 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59
    quote:
    After further testing...
    When statement looks like this

    thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").selectSingleNode("EmployeeID")

    I get "nothing"


    You will always get nothing if you don't include the namespace in the query...

    You might get further with something more like:
    thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").selectSingleNode(".//ns1:EmployeeID")


    Remember, you're not going anywhere without:

    1. Setting the SelectionNamespace for the DOM you're querying off; and

    2. Including the namespace prefix at every node in the selectSingleNode() et al query

  • 11-29-2004 08:29 AM In reply to

    I haven't tried accessing the DOM with VB.NET but with C# you need to cast to IXMLDOMDocument3. Version 3 has the setProperty property. See this discussion for help and code in C#.
    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=88
  • 11-29-2004 08:36 AM In reply to

    Just tried what you suggested:
    Dim myUserNode As IXMLDOMNode = thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").selectSingleNode(".//ns1:EmployeeID")

    And received the following error
    Run-time exception thrown : System.Runtime.InteropServices.COMException - Reference to undeclared namespace prefix: 'ns1'.


    I also tried declaring it as IXMLDOMDocument3 and received the same error.
  • 11-29-2004 08:58 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59
    Like I said, that indicates that you have not declared the namespace prefix ns1 for the DOM you're querying off.

    What have you done in the way of setting the SelectionNamespace for thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest")?

    According to me, you're going to have to do something yourself, coz I don't think the Vis Stu stuff does this for you for managed code? (Remember, personally I use Script).
  • 11-29-2004 09:20 AM In reply to

    I'm kinda lost at what your talking about. The SelectionNamespace is just the XML node path correct? It seems that what I have below would take care of this issue.

    Currently the Namespace is defined up top as

    <InfoPathNamespace("xmlns:xsf=""http://schemas.microsoft.com/office/infopath/2003/solutionDefinition"" xmlns:msxsl=""urn:schemas-microsoft-com:xslt"" xmlns:xd=""http://schemas.microsoft.com/office/infopath/2003"" xmlns:xdUtil=""http://schemas.microsoft.com/office/infopath/2003/xslt/Util"" xmlns:xdXDocument=""http://schemas.microsoft.com/office/infopath/2003/xslt/xDocument"" xmlns:xdMath=""http://schemas.microsoft.com/office/infopath/2003/xslt/Math"" xmlns:xdDate=""http://schemas.microsoft.com/office/infopath/2003/xslt/Date"" xmlns:s0=""http://tempuri.org/WSHardwareSoftwareRequest/Service1"" xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16"" xmlns:ns1=""http://www.tempuri.org/DataSet1.xsd"" xmlns:ns2=""http://tempuri.org/WSSelectEmployeeInfo/Service1"" xmlns:_xdns0=""http://schemas.microsoft.com/office/infopath/2003/changeTracking"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:ns3=""http://www.tempuri.org/DataSet2.xsd"" xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:ns5=""http://tempuri.org/WSProjectInfo/Service1"" xmlns:mime=""http://schemas.xmlsoap.org/wsdl/mime/"" xmlns:tm=""http://microsoft.com/wsdl/mime/textMatching/"" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:ns6=""http://schemas.xmlsoap.org/wsdl/soap/"" xmlns:http=""http://schemas.xmlsoap.org/wsdl/http/"" xmlns:ns7=""http://schemas.xmlsoap.org/wsdl/""")>



    How does your script version look for this?
  • 11-29-2004 09:24 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59
    sakieboy,

    I just looked at CodeWzrd's suggested link above (which I participated in). I assume what he said for managed code is what you want.

    The vital bit is:
    IXMLDOMDocument3 domXML = (IXMLDOMDocument3) objDO.DOM;
    domXML.setProperty( "SelectionNamespaces", "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" " + "xmlns:tns=\"http://tempuri.org/\"");


    You need to setProperty for "SelectionNamespaces" on the secondary DOM you're using. That's the important bit.

    You need more namespaces than he shows. You need ns1. Follow? Either type it in by hand (e.g. I think in your managed code you get all the namespaces declared in
    [InfoPathNamespace("...")
    that VS puts against your public class), or do as I do in that thread above, and copy the namespaces programatically (using getProperty) from the main DOM.
  • 11-29-2004 09:31 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59
    [Our posts just crossed!]

    [Ooh, look, I got a green star!]

    How's about trying from his example something pretty like:

    IXMLDOMDocument3 domXML = (IXMLDOMDocument3) objDO.DOM;
    domXML.setProperty( "SelectionNamespaces", thisXDocument.DOM.getProperty("SelectionNamespaces"));


    Not tried, don't know about casting to (IXMLDOMDocument3), but the gist is I'm setting the secondary's SelectionNamespaces property to the value of that property on the main DOM. That's what I do in script:

    // Next line put in by IP
    XDocument.DOM.setProperty("SelectionNamespaces", ...');
    // Next line added by me (for each secondary adapter)
    XDocument.GetDOM("LogonToProject").setProperty("SelectionNamespaces", XDocument.DOM.getProperty("SelectionNamespaces"));
  • 11-29-2004 12:22 PM In reply to

    I'm trying your example to see what happens.

    I can't compile it because it doesn't recognize SetProperty as a Method of DOM.

    Defined as

    Private thisXDocument As XDocument

    thisXDocument.DOM.setProperty("SelectEmployeesWithHardwareSoftwareRequest", "xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1""")
    thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest").setProperty("SelectEmployeesWithHardwareSoftwareRequest", thisXDocument.DOM.getProperty("SelectEmployeesWithHardwareSoftwareRequest"))
  • 11-29-2004 01:06 PM In reply to

    I think you two are getting mixed up with the coding languages you are using...

    sakiboy, you started this post using VB.NET (managed code).
    jonbrave, you are using JScript.

    The two are not compatible.

    Once again, let me state that you should NEVER set the selection namespaces for thisXDocument.DOM (BAD! BAD! BAD!) InfoPath and Visual Studio do this for you. If you mess with this you will no longer be able to make selections within the main DOM. Just don't do it!

    You want to set the selection namespaces for your secondary data sources ONLY...

    If you are using managed code, do it like this:

    IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
    domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
    IXMLDOMNode oNode = domFoo.selectSingleNode("abc:FieldName");


    If you are using JScript, do it like this:

    var domFoo = XDocument.GetDOM("Foo");
    domFoo.setProperty("SelectionNamespaces", 'xmlns:abc="http://foo.bar.com/abc"');
    var oNode = domFoo.selectSingleNode("abc:FieldName");


    Greg Collins [InfoPath MVP]
  • 11-29-2004 01:33 PM In reply to

    I attempted what you suggested and I get a syntax error...

    'selectSingleNode' is ambiguous across the inherited interfaces 'Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument' and 'Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode'.

    This occurs on my 3rd line

    Dim domFoo As IXMLDOMDocument2 = CType(thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest"), IXMLDOMDocument2)

    domFoo.setProperty("SelectionNamespaces", "xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1""")

    Dim oNode As IXMLDOMNode = domFoo.selectSingleNode("ns1:EmployeeID")
  • 11-29-2004 04:44 PM In reply to

    You are setting a selection namespace for "ns4" but are trying to use "ns1". Why is that?

    Greg Collins [InfoPath MVP]
Page 1 of 2 (24 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.