Cascading dropdown list on and off-line via dataset from webservice... - InfoPath Dev
in

InfoPath Dev

Cascading dropdown list on and off-line via dataset from webservice...

Last post 08-07-2009 05:41 AM by dana.eddy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-30-2009 12:44 PM

    Cascading dropdown list on and off-line via dataset from webservice...

     To all the XML Gurus...

    I need a Cascading dropdown list solution for a form that will work both in ip 2007 services and off-line.
    For simplicity/testing I use field2 = /my:myFields/my:field1 and field2 = /my:myFields/my:field

    I populate both lists from the respective service (this works fine) Then on field1_Changed try to rebuild the field2 list as below:

            public void field1_Changed(object sender, XmlEventArgs e)
            {
                XPathNavigator parent = e.Site.SelectSingleNode("..");

                // Remove existing values first
                List<XPathNavigator> nodesToDelete = new List<XPathNavigator>();
                foreach (XPathNavigator field2SourceNode in parent.Select("my:field2", NamespaceManager))
                {
                    // Cannot just call DeleteSelf on the navigator because it alters the iteration state.
                    // Instead, collect the navigators for future deletion.
                    nodesToDelete.Add(field2SourceNode.Clone());
                }
                // Now remove all the nodes.
                foreach (XPathNavigator field2SourceNode in nodesToDelete)
                {
                    field2SourceNode.DeleteSelf();
                }

                //
                // The data is in the datasource
                XPathNavigator entryNavigator = this.DataSources["GetUnitList"].CreateNavigator();

                // Add the namespaces so we can query the datasource
                XmlNamespaceManager umanager = new XmlNamespaceManager(entryNavigator.NameTable);
                umanager.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution");
                umanager.AddNamespace("tns", "http://tempuri.org/");
                umanager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-02T10:15:45");
                umanager.AddNamespace("xd", "http://schemas.microsoft.com/office/infopath/2003");

                string matchingfield2XPath = String.Format("/dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table/[@UnitType = '{0}']", e.Site.Value);
                                                        
                //// For each matching node, add it to the collection
                foreach (XPathNavigator field2Navigator in this.DataSources["GetUnitList"].CreateNavigator().Select(matchingfield2XPath, umanager))
                {
                    using (XmlWriter writer = parent.AppendChild())
                    {
                        writer.WriteElementString("field2Source", NamespaceManager.LookupNamespace("my"), field2Navigator.Value);
                    }
                }
            }

     The value of field1 should filter the entries in field2... I believe the value for matchingfield2XPath is the problem?? 

    matchingfield2XPath  = /dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table/[@UnitType = 'a577a221-598e-449c-8f93-cd68ad70a97c'] 

    /////////// RESULTS FROM GetUnitList WEBSERVICE

     

      <?xml version="1.0" encoding="utf-8" ?>
    - <DataSet xmlns="http://tempuri.org/">
    - <xs:schema id="Unit" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    - <xs:element name="Unit" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    - <xs:complexType>
    - <xs:choice minOccurs="0" maxOccurs="unbounded">
    - <xs:element name="Table">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="RecordID" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
      <xs:element name="UnitType" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
      <xs:element name="UnitTypeName" type="xs:string" minOccurs="0" />
      <xs:element name="UnitName" type="xs:string" minOccurs="0" />
      <xs:element name="Active" type="xs:boolean" minOccurs="0" />
      <xs:element name="ISIC" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
      <xs:element name="ISICName" type="xs:string" minOccurs="0" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xs:schema>
    - <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    - <Unit xmlns="">
    - <Table diffgr:id="Table1" msdata:rowOrder="0">
      <RecordID>5d8c579a-0a64-42bc-b7bb-99482ff5fe8f</RecordID>
      <UnitType>a577a221-598e-449c-8f93-cd68ad70a97c</UnitType>
      <UnitTypeName>USS</UnitTypeName>
      <UnitName>ZEPHYR</UnitName>
      <Active>true</Active>
      <ISIC>2577f9cd-c0d3-4718-9dfd-8d47501225dd</ISIC>
      <ISICName>ISIC Test Entry</ISICName>
      </Table>
    - <Table diffgr:id="Table2" msdata:rowOrder="1">
      <RecordID>4e19f8d0-6124-4c33-b089-f0014fbb4a3d</RecordID>
      <UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
      <UnitTypeName>USNS</UnitTypeName>
      <UnitName>1ST LT HARRY L. MARTIN</UnitName>
      <Active>true</Active>
      </Table>
    - <Table diffgr:id="Table3" msdata:rowOrder="2">
      <RecordID>39622e87-6086-4d6a-98a6-aae4777d49f9</RecordID>
      <UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
      <UnitTypeName>USNS</UnitTypeName>
      <UnitName>ABLE</UnitName>
      <Active>true</Active>
      </Table>
    ...
    - <Table diffgr:id="Table816" msdata:rowOrder="815">
      <RecordID>42a63396-3eb8-45cb-aa96-a5cf0de812c1</RecordID>
      <UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
      <UnitTypeName>USNS</UnitTypeName>
      <UnitName>YUKON</UnitName>
      <Active>true</Active>
      </Table>
    - <Table diffgr:id="Table818" msdata:rowOrder="817">
      <RecordID>40684e1c-b36e-4151-ad9f-d452e44ead51</RecordID>
      <UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
      <UnitTypeName>USNS</UnitTypeName>
      <UnitName>ZEUS</UnitName>
      <Active>true</Active>
      </Table>
      </Unit>
      </diffgr:diffgram>
      </DataSet>

  • 08-06-2009 09:21 AM In reply to

    Re: Cascading dropdown list on and off-line via dataset from webservice...

    Hi -- What exactly is happening when you run your code? Are you getting an error? An unexpected result? Are you using InfoPath 2007? If so, did you copy the XPath from the data source task pane (right click on the field you need and select Copy XPath)...

    Wait, on re-read, this:

     string matchingfield2XPath = String.Format("/dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table/[@UnitType = '{0}']", e.Site.Value);

    should probably be:

    string matchingfield2XPath = String.Format("/dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table[@UnitType = '{0}']", e.Site.Value);

    Hard to see the difference, but I removed the / before [@UnitType ...

    Hilary Stoupa

  • 08-07-2009 05:41 AM In reply to

    Re: Cascading dropdown list on and off-line via dataset from webservice...

    Hilary,

    Thank you for the response..!! Your recommendation worked. I don't want to try to count the number of times a missing or extra / ; , ) have made my day. Thanks for the extra set of I's ... and the solution!!!

     This may not be the proper place to ask or post (I will be glad to move ot if necessary). But here goes.  1. As seen above XPath strings in InfoPath can get long and unforgiving. Is there a best practice for creating variables or even a class to set/get (It must support standalone and web based)  to make the code more 'friendly'.2. When retrieving values from a web service that are nil, the xml will not contain the element (ie. see the last 2 nodes in the submitted file). What is the best practice for addressing this situation. (fix it in the stored procedure, fix it server-side in the webmethod, or fix it in the form) And how...

    Thanks Again,

    Dana

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