Browser form dropdown filtering using webservice - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Browser form dropdown filtering using webservice

Last post 09-03-2007 11:38 PM by davidair. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 08-20-2007 01:09 PM

    Browser form dropdown filtering using webservice

    Hi,

     I've Browser-enabled form that has a repeating table.  This repeating table has a Category and Sub-Category (which is filtered based on Category through data connection via WebService and database). 

    Problem is each time the table repeats and the corresponding Category and Sub-Category gets called then the Sub-Category gets updated in the previous repetitions as well since the same data connection is used.

    So, what are my options to avoid this?  How can I make every Table repetition keep it's own Sub-Category?  The solution could be behind the form code ... doesn't matter.

     

    I'll really appreciate any help.

     

    thanks. 

  • 08-23-2007 08:19 AM In reply to

    Re: Browser form dropdown filtering using webservice

    Hello!

    Unfortunately, there is no easy way to achieve what you are trying to do for the very reason that data sources for dropdown values cannot be filtered. There is one workaround but it's pretty ugly because it involves modifying your main data source and polluting your XML. Here is how it would work:

    Suppose your current data source looks like this:

    myFields
      myRepeatingTable
        myCategory
        mySubCategory

    A dropdown bound to mySubCategory will always have the same values in each row no matter what. What you can do, though, is to add those values under the repeating table, like this:

    myFields
      myRepeatingTable
        myCategory
        mySubCategory
        mySubCategoryValues

    (Make sure mySubCaregoryValues node is repeating)

    Now you can set the dropdown's values to "Look up values in the form's data source" and point them to mySubCategoryValues. Finally, you will have to write code that replaces those values whenever myCategory changes. Note that you will always need to postback to the server whenever category changes simply because code can only run server-side.

    Hope this helps a bit.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 08-23-2007 09:48 AM In reply to

    Re: Browser form dropdown filtering using webservice

    Hi Cocodog123,

    We have a Web service that we developed which does the filtering based on an XML filter that you pass to it. You can install the free dev version from our downloads - look for DBXL 2.1. You'll want to look at the documentation on EnumDB. Let us know if you need help setting up a UDC for it.

    Cheers! 

    Patrick Halstead
    Project Manager at Qdabra
  • 08-23-2007 11:26 AM In reply to

    Re: Browser form dropdown filtering using webservice

     Thanks for you rply.  However, is there a more detail article that I can follow because I'm new to Infopath and behind the form coding.

     Another thing I was think was to get all the values from my "C" list and then just filter w/in the form.  However, this is browser based form and such filtereing is not supported.  Do you know any workaround for that.

     

    Again, thanks a lot.
     

  • 08-23-2007 04:17 PM In reply to

    Re: Browser form dropdown filtering using webservice

    I have created and uploaded a working sample here: http://www.infopathdev.com/files/folders/community_uploads/entry22603.aspx

    the zip file contains the ready-to-deploy XSN as well as the source code. I hope this helps you!

    David.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 08-24-2007 01:48 PM In reply to

    Re: Browser form dropdown filtering using webservice

     Thank you so much for giving this solution but I'm having the following problem. 

     Here is my setup:  ListA (populated vis Data conn (via web service to DB)).  Upon selection of ListA, it calls the GetLibstB(ListA ListA_ID) a web service.  I'm populating the drop-down, on the form, for listB using your code.

    I've something like this:

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

                foreach (XPathNavigator listBSourceNode in parent.Select("my:listB_Source", NamespaceManager))
                {
                    listBSourceNode.DeleteSelf();
                }

                string matchingListBSource = String.Format("/dfs:myFields/dfs:dataFields/tns:GetListBResponse/tns:GetListBResults/NewDataSet/values[@ListA_ID = '{0}']", e.Site.Value);

                foreach (XPathNavigator listBNavigator in this.DataSources["GetListB"].CreateNavigator().Select(matchingListBSource,NamespaceManager))
                {
                    using (XmlWriter writer = parent.AppendChild())
                    {
                        writer.WriteElementString("listB_Source", NamespaceManager.LookupNamespace("my"), spotNavigator.Value);
                    }
                }
            }
     

    During dubgging, the mathingListBSource has the right value.  Also, I placed the GetListB data connection onto the form and it does return the right values.

     

    Any idea why the  listBNavigator always comes up null (that's what the debugger shows).

     

    Thanks again for all of your help. 

  • 08-24-2007 07:55 PM In reply to

    Re: Browser form dropdown filtering using webservice

     Hey Buddy,

     I finally got everything going, EXCEPT, it doesn't populate the dropdown list at all.  Keeping your exmaple in mind then it doesn't populate "mySubCategoryValues" even though the foreach loops thorugh the right number of times.  So, data is there but it doesn't get added to the dropdown?  Any idea?  Also, how can i add my returned values into "id" and "value" of  the drop-down repectively.

     

    thanks.


     

  • 08-26-2007 12:23 PM In reply to

    Re: Browser form dropdown filtering using webservice

     Hey,

      I've everything working.  I need help with two things:

      1.  When rebuilding the drop-down it doesn't delete all the previous ones.  At leaves one from the previous drop-down and adds the new ones to it.  This happens in your example as well.  Any suggestion?

      2.  My drop-down is populated from this data conn:

           ListB

             + queryFields
             -  resultFields 
                    . list_ID
                    . list_Title
                    . listA_ID

            The current code con-cats all these values and place it in the drop down .  How  Can I  place these values as I want to. For ex: drop-down ID = list_ID and drop-down Value = list_TItle.

     

    thanks a lot for all of your help. 

        
     

          
     

         
     

  • 08-29-2007 09:00 AM In reply to

    Re: Browser form dropdown filtering using webservice

    Hey cocodog,

    Sorry for the late response...

    1. There is bug in my deletion code. Here is the correct way to delete the nodes:

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

    // Now remove all the nodes.
    foreach (XPathNavigator citySourceNode in nodesToDelete)
    {
       citySourceNode.DeleteSelf();
    }

    2. You only have one repeating node listB_Source. Instead, make it so that it has two children:

    listB_Source
      displayValue
      dataValue

    In designer, specify displayValue and dataValue in the UI when you are setting up the listbox properties. Finally, in your code, append the displayValue and dataValue nodes under each new instance of listB_Source and set their values respectively to list_ID and list_TItle.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-02-2007 12:53 PM In reply to

    Re: Browser form dropdown filtering using webservice

     Hi David,

      Your code has been a great help.  But I was wondering if you could be kind and help me understand some of the concepts so that I can tackle any variations instead of bugging you each time:
    Here is the form structure that I'm working with:

    Main Data Source:                                                  GetResult (I will use this data connection to populate the ListB, which will populate the form drop down list):
     - myFields                                                               - input
       - ParentSection                                                          - inputListA_ID     
          - MasterSection (repeating)                                  - output (notes: these results are filtered based on what's selected in ListA) 
             - Goup1                                                               - ID       (this value will be assigned to listB_ID attribute in behind the form code)
                  - ListB (repeating)                                            - Name (this value will be assigned to listB_Name attribute in behind the form code) 
                      - listB_ID                                                     - listA_ID 
                      - listB_Name

    Based on your code, I've written the following and have few questions:           

    1. Do I need to get a selection of each element from the GetResult Data connection (as i've written one below)?  Because I need "ID' and "Name" elements from this data connection.

    string matchingSpotXPath = String.Format("/dfs:myFields/dfs:dataFields/tns:GetResult / tns:output / NewDataSet/output [listA_ID = '{0}']/Name", e.Site.Value);

    2.  How does the appending works here.  I've a ListB node and then I've two attributes listB-ID and listB-Name.  So, I'm stuck at trying to figure out on how to append the
    ListB element and their corresponding attributes and assign their values.  I've written the following but I need more guidance on getting access to attributes, appending attributes, and assiging values.

    foreach (XPathNavigator spotNavigator in this.DataSources["GetResult"].CreateNavigator().Select(matchingSpotXPath, NamespaceManager))
    {
         using (XmlWriter writer = parent.AppendChild())
         {
             writer.WriteElementString("ListB",NamespaceManager.LookupNamespace("my"), spotNavigator.value);
       
           }

    }

     

    Thanks. 

  • 09-02-2007 08:33 PM In reply to

    Re: Browser form dropdown filtering using webservice

    Hi David,

      I Fig. out how to access childeren etc.  The only issue left to resolve is that each time main table repeats then the code still appends the results to the first drop down instead of appending it to the current insatance.

    So, let's say that my table repeated 3 times. 

       Table Repetition 1: First time the drop downs get populated just fine

       Table Repetition 2: it's drop down is empty and the results get attached to the frist Repetition's drop down

      and so on.

      I'm using the "e.Site.Select......."  So, I would assume that each time it'll poin to the current iteration but appearently it doesn't.  Do you know the reason by any chance?

     

    Thanks.

  • 09-03-2007 11:38 PM In reply to

    Re: Browser form dropdown filtering using webservice

    Yes, I think I know what your problem might be: you are using absolute xpath instead of a relative one. An absolute xpath starts from the root node (typically it is prefixed with /) while the relative one starts from e.Site. Just think of what e.Site represents and compute the closest possible path from there.

    I hope this helps...

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.