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 2 of 2 (24 items) < Previous 1 2
Sort Posts: Previous Next
  • 11-30-2004 06:25 AM In reply to

    First Off... My stored procedure looks something like this...

    CREATE PROCEDURE udp_SelectEmployeesWithHardwareSoftwareRequest
    (@User nvarchar(50))
    AS
    SET NOCOUNT ON

    SELECT NameAndRequest
    FROM viewAllEmployeesActive

    UNION

    SELECT tblHardwareSoftwareRequest.RequestedForEmployeeID
    FROM tblHardwareSoftwareRequest

    SELECT EmployeeID, FileAs, NTAccount FROM Emp.dbo.viewAllEmployeesActive viewAllEmployeesActive_1 WHERE NTAccount=@User

    RETURN
    GO


    The last select statement is the one that I'm trying to retrieve a value out of.

    In IP, when I select the data validation and onafterchange it displays a method for onafterchange in the code. It seems that all I would have to do is grab the string at the beginning of the code, i.e.

    MatchPath:="/dfs:myFields/dfs:dataFields/ns4:SelectEmployeesWithHardwareSoftwareRequestResponse/ns4:SelectEmployeesWithHardwareSoftwareRequestResult/ns1:DataSet1/ns1:Table1/ns1:EmployeeID"

    So it would seem that I could grab everything after the "MatchPath:=" and use it to retrieve the field. You mentioned that I need to Get the secondary connection. I've seen several examples within our discussion, but none seem to work. "ns4" looks like part of the namespace, where ns1 is part of the field.


    Thanks
  • 11-30-2004 05:41 PM In reply to

    Each of those namespaces you see need to be defined for the DOM:

    * dfs
    * ns4
    * ns1

    I'm assuming that there will also be a ns2 and ns3 in there somewhere.

    You must set all of these namespaces at the same time.

    Greg Collins [InfoPath MVP]
  • 12-01-2004 06:23 AM In reply to

    I believe that .Net has already declared these items that you mentioned.

    The point I'm at currently is: I have the following 2 statements
    Dim domFoo As IXMLDOMDocument2 = CType(thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest"), IXMLDOMDocument2)
    domFoo.setProperty("SelectionNamespaces", "xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1""")

    When I put "domFoo" in the watch window, and look at the xml attribute, I can see the results of my previously entered stored procedure query in one of the above blogs which consisted of a SELECT-UNION-SELECT-SELECT.

    The question now is how do I retrieve a value from the resulting XML string (displaying within the watch window)?

    Here is the resulting XML string (within the watch window):

    <dfs:myFields xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:ns4="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16" 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:ns1="http://www.tempuri.org/DataSet1.xsd" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><dfs:queryFields><ns4:SelectEmployeesWithHardwareSoftwareRequest></ns4:SelectEmployeesWithHardwareSoftwareRequest></dfs:queryFields><dfs:dataFields><SelectEmployeesWithHardwareSoftwareRequestResponse xmlns="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"><SelectEmployeesWithHardwareSoftwareRequestResult><DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd"><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest1" msdata:rowOrder="0"><EmployeeID>6126</EmployeeID><NameAndRequest>Abella, Jude - </NameAndRequest><HardwareSoftwareRequestID>6</HardwareSoftwareRequestID><RequestStatus>Pending</RequestStatus><MyOrder>1</MyOrder></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest2" msdata:rowOrder="1"><EmployeeID>6126</EmployeeID><NameAndRequest>Abella, Jude - Need New PC</NameAndRequest><HardwareSoftwareRequestID>5</HardwareSoftwareRequestID><RequestStatus>Pending</RequestStatus><MyOrder>1</MyOrder></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest3" msdata:rowOrder="2"><EmployeeID>3397</EmployeeID><NameAndRequest>Wheeler, Darryl - Computer Software</NameAndRequest><HardwareSoftwareRequestID>4</HardwareSoftwareRequestID><RequestStatus>Pending</RequestStatus><MyOrder>1</MyOrder></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest4" msdata:rowOrder="3"><EmployeeID>3397</EmployeeID><NameAndRequest>Wheeler, Darryl - test</NameAndRequest><HardwareSoftwareRequestID>3</HardwareSoftwareRequestID><RequestStatus/><MyOrder>1</MyOrder></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest5" msdata:rowOrder="4"><EmployeeID>1100</EmployeeID><NameAndRequest>Simon, Marcia</NameAndRequest><HardwareSoftwareRequestID>99991100</HardwareSoftwareRequestID><RequestStatus/><MyOrder>2</MyOrder><MyOrder2>3</MyOrder2></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest6" msdata:rowOrder="5"><EmployeeID>3397</EmployeeID><NameAndRequest>Wheeler, Darryl - test1</NameAndRequest><HardwareSoftwareRequestID>1</HardwareSoftwareRequestID><RequestStatus>Closed</RequestStatus><MyOrder>4</MyOrder></dbo_udp_SelectEmployeesWithHardwareSoftwareRequest><Table1 diffgr:id="Table11" msdata:rowOrder="0"><EmployeeID>3397</EmployeeID><FileAs>Wheeler, Darryl</FileAs><NTAccount>Dwheeler</NTAccount></Table1></DataSet1></SelectEmployeesWithHardwareSoftwareRequestResult></SelectEmployeesWithHardwareSoftwareRequestResponse></dfs:dataFields></dfs:myFields>


    The green bolded section is the information that I need.


    Thanks
  • 12-01-2004 01:03 PM In reply to

    IMPORTANT 1:
    It is good practice to set EVERY namespace used in your data source, whether you use them or not. This saves headaches later when you decide you need to access other fields, but never set the namespace required to access for them.

    IMPORTANT 2:
    Also, any "default namespace" -- one without a prefix, should ALWAYS have a prefix added to it. You will NOT be able to select fields associated with that default namespace unless you provide a prefix and then use that prefix.

    You have two of these in your sample XML:
    xmlns="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"
    xmlns="http://www.tempuri.org/DataSet1.xsd"

    I would assign the random prefixes (make sure they aren't already assigned):
    xmlns:ws1="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"
    xmlns:ns1="http://www.tempuri.org/DataSet1.xsd"

    (I use "ns1" here because it looks like that's what InfoPath used according to a previous post of yours).

    This means that any "default namespace" child of the element "SelectEmployeesWithHardwareSoftwareRequestResponse" will need to be accessed using the "ws" namespace. And that any "default namespace" child of the element "DataSet1" will need to be accessed using the "ns1" namespace.



    That would bring your code to look like this:

    Dim domFoo As IXMLDOMDocument2 = CType(thisXDocument.GetDOM("SelectEmployeesWithHardwareSoftwareRequest"), IXMLDOMDocument2)
    domFoo.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16"" 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:ns1=""http://www.tempuri.org/DataSet1.xsd"" xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:ws1=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:ns1=""http://www.tempuri.org/DataSet1.xsd""")



    Now that you've defined "ns1" as the prefix for the default namespace on the dataset, you can use "ns1" as defined in your matchpath:

    MatchPath:="/dfs:myFields/dfs:dataFields/ns4:SelectEmployeesWithHardwareSoftwareRequestResponse/ns4:SelectEmployeesWithHardwareSoftwareRequestResult/ns1:DataSet1/ns1:Table1/ns1:EmployeeID"



    I think your biggest issue was not assigning a prefix to the default namespaces.


    Greg Collins [InfoPath MVP]
  • 12-02-2004 07:05 AM In reply to

    I see your point, but my results from my watch window appear to be pretty much the same. I've changed my Web Service to reflect dataset2 instead of dataset1 for differential purposes.



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

    domFoo.setProperty("SelectionNamespaces",
    "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16"" 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:ns1=""http://www.tempuri.org/DataSet1.xsd"" xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:ws1=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1""
    xmlns:ns3=""http://www.tempuri.org/DataSet2.xsd""")

    As you can see by my last line that I should be able to use ns3. The problem is that when I view it in the watch window it doesn't reflect the proper namespace:


    <dfs:myFields xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:ns4="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16" 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">

    <dfs:queryFields><ns4:SelectEmployeesWithHardwareSoftwareRequest></ns4:SelectEmployeesWithHardwareSoftwareRequest></dfs:queryFields>

    <dfs:dataFields>
    <SelectEmployeesWithHardwareSoftwareRequestResponse xmlns="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1">
    <SelectEmployeesWithHardwareSoftwareRequestResult><DataSet2 xmlns="http://www.tempuri.org/DataSet2.xsd"><dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest1" msdata:rowOrder="0">
    <EmployeeID>1100</EmployeeID>
    <NameAndRequest>Simon, Marcia</NameAndRequest> <HardwareSoftwareRequestID>99991100</HardwareSoftwareRequestID>
    <RequestStatus/>
    <MyOrder>2</MyOrder>
    <MyOrder2>3</MyOrder2>
    </dbo_udp_SelectEmployeesWithHardwareSoftwareRequest>
    <dbo_udp_SelectEmployeesWithHardwareSoftwareRequest diffgr:id="dbo_udp_SelectEmployeesWithHardwareSoftwareRequest2" msdata:rowOrder="1">
    <EmployeeID>3397</EmployeeID>
    <NameAndRequest>Wheeler, Darryl - test1</NameAndRequest>
    <HardwareSoftwareRequestID>1</HardwareSoftwareRequestID>
    <RequestStatus>Closed</RequestStatus>
    <MyOrder>4</MyOrder>
    </dbo_udp_SelectEmployeesWithHardwareSoftwareRequest>
    <Table1 diffgr:id="Table11" msdata:rowOrder="0">
    <EmployeeID>3397</EmployeeID>
    <FileAs>Wheeler, Darryl</FileAs>
    <NTAccount>Dwheeler</NTAccount>
    </Table1>
    </DataSet2>
    </SelectEmployeesWithHardwareSoftwareRequestResult>
    </SelectEmployeesWithHardwareSoftwareRequestResponse>
    </dfs:dataFields>
    </dfs:myFields>

    I'm not sure of how to change to Namespace, because it doesn't appear to be working for the DataFields section.

    Thanks
  • 12-02-2004 11:51 AM In reply to

    If I take your XML code from the previous post and use it to create "test.xml", then create a new blank form (JScript), and import that as a secondary data source, I am able to access the value of EmployeeID with no problem...

    var domFoo = XDocument.GetDOM("test");

    domFoo.setProperty("SelectionNamespaces", 'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:ns4="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/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:ns1="http://www.tempuri.org/DataSet1.xsd" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:ws1="http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1" xmlns:ns3="http://www.tempuri.org/DataSet2.xsd"');

    var x = domFoo.selectSingleNode("//ns3:EmployeeID");
    XDocument.UI.Alert(x.text);


    I have not tried this in VB.NET as you are using... but it should work just fine.

    And yes... the watch window will not show the namespace that you defined for selection purposes. It will show the one that is defined in the XML -- which is the default namespace.

    Greg Collins [InfoPath MVP]
  • 12-02-2004 12:59 PM In reply to

    According to what you're saying, if I use what I currently have and add another line...

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

    domFoo.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:ns4=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-22T19:23:16"" 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:ns1=""http://www.tempuri.org/DataSet1.xsd"" xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:ws1=""http://tempuri.org/WSSelectEmployeesWithHardwareSoftwareRequest/Service1"" xmlns:ns3=""http://www.tempuri.org/DataSet2.xsd""")

    Dim MyTest As IXMLDOMDocument2 = CType(domFoo.selectSingleNode("//ns3:EmployeeID"), IXMLDOMDocument2)

    I have a syntax error which follows...

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

    when I change the last line to :
    domFoo.selectSingleNode("//ns3:EmployeeID")

    it runs through properly (I don't get an error, syntax-wise), of course, it's of no use...

    I understand what the error is saying, the SelectSingleNode is inherited from a couple of places, but how do I remedy this?
  • 12-03-2004 02:49 PM In reply to

    I'm not sure I follow what you are trying to do. What I understood your original request to be was to find out how to access EmployeeID via selectSingleNode -- which it sounds like you are now able to do.

    What I don't understand is why you are trying to convert it to an IXMLDOMDocument2.

    Therefore... please rephrase what it is you are trying to accomplish here so that I can offer appropraite help.

    Greg Collins [InfoPath MVP]
  • 03-19-2007 11:39 AM In reply to

    • grhind
    • Not Ranked
    • Joined on 03-19-2007
    • Posts 1
    Try this... it's vb.net managed code but you get the idea.

    Public Function GetTemplateXMLFileDOM() As IXMLDOMDocument3
    Dim TemplateDOM As IXMLDOMDocument3

    TemplateDOM = prXDoc.CreateDOM()
    TemplateDOM.async = False
    TemplateDOM.validateOnParse = False
    TemplateDOM.load("template.xml")

    Dim MyAttribute As InfoPathNamespaceAttribute
    MyAttribute = CType(Attribute.GetCustomAttribute(prParentClassType, GetType(InfoPathNamespaceAttribute)), InfoPathNamespaceAttribute)
    prInfoPathNamespace = MyAttribute.UserNamespace

    TemplateDOM.setProperty("SelectionNamespaces", prInfoPathNamespace)

    Return TemplateDOM
    End Function
Page 2 of 2 (24 items) < Previous 1 2
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.