Creating a Select All button for a multiple selection listbox with unknown values - InfoPath Dev
in

InfoPath Dev

Creating a Select All button for a multiple selection listbox with unknown values

Last post 06-14-2013 12:47 PM by Omegacron. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-11-2013 08:27 AM

    • Omegacron
    • Not Ranked
    • Joined on 06-11-2013
    • Houston, TX
    • Posts 5

    Creating a Select All button for a multiple selection listbox with unknown values

    I have an InfoPath 2010 form that contains multiple secondary data sources. One of the fields on the form is a multiple selection listbox that pulls its values from a filtered secondary data source. This data source is a SharePoint list that functions like a shopping cart, with each user having several items in the list and they can only see their own items. What the filter does is show any "shopping cart" items where the 'Modified By' is equal to the user opening the form. In this way, I am able to show the user their own cart items and have them select each one to "staple" the item value into the form's XML. The business unit has requested a "Select All" button that will select all of the visible items without the user having to individually check each one, and that's where I'm running into issues. The values in the listbox could be anything out of 1000 possible choices, so there's no practical way to hard-code values.

    The filter is currently being applied in the properties of the multiple selection listbox, where I'm telling it to get its values from a secondary data source. I can move the filter if needed. Also, I can change the "Select All" button into something like "Import My Items" if needed, where the button pulls in a filtered subset of the shopping cart list and adds the items programmatically instead. Either way will do, but I haven't had much success with either method.

    I have a basic to moderate skill in C# but I'm definitely no expert. Essentially what I'm looking for is code snippets for one of the two options below:

    • Looping through the displayed items and checking each one to select it
    • Pulling in a filtered subset of the secondary data source with the items already selected 

    I think I'm close - I've been able to pull in all items from the secondary data source with the items already selected, but any attempts to add a filter to the XPathNodeIterator either have no effect or result in an error. I can post my code if needed, but I have a feeling it may just muddy the waters.

    Thanks in advance to anyone who can help.

  • 06-13-2013 11:08 AM In reply to

    • Omegacron
    • Not Ranked
    • Joined on 06-11-2013
    • Houston, TX
    • Posts 5

    Re: Creating a Select All button for a multiple selection listbox with unknown values

    Here is my ClickedEvent code. Everything is working as desired except for the user filter on the XPathNodeIterator line. I only want the data source to return nodes where where the 'Modified By' field in the secondary data source equals the 'Requested By' field in the form (current user). On the XPathNodeIterator I've tried the two filters below and variations on them (using our actual domain, not "DOMAIN").

    [d:Editor/pc:Person/pc:AccountId = //my:myFields/my:RequestedBy/pc:Person/pc:AccountId]
    [d:Editor/pc:Person/pc:AccountId = concat("DOMAIN\", xdUser:get-UserName())]

     

    public void BTN_SELECT_Clicked(object sender, ClickedEventArgs e)
            {
                // Define Main Datasource Objects
                XPathNavigator MainDS = MainDataSource.CreateNavigator();
                XPathNavigator Reports = MainDS.SelectSingleNode("//my:myFields/my:Reports", NamespaceManager);
                XPathNavigator Report = MainDS.SelectSingleNode("//my:myFields/my:Reports/my:Report", NamespaceManager);

                //Define Shopping Cart Objects
                XPathNavigator CartDS = DataSources["Shopping Cart"].CreateNavigator();
                XPathNavigator CartItems = CartDS.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW", NamespaceManager);
                XPathNavigator CartItem = CartDS.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title", NamespaceManager);
                XPathNodeIterator Cart = DataSources["Shopping Cart"].CreateNavigator().Select("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW", NamespaceManager);

                //Initialize counter and begin cycling through Shopping Cart
                int counter = 1;
                while (Cart.MoveNext())
                {
                    string reportName = Cart.Current.SelectSingleNode("d:Title", NamespaceManager).Value;
                    Reports.AppendChildElement("my", "Report", Reports.NamespaceURI, reportName);
                    counter++;
                }

  • 06-13-2013 11:42 AM In reply to

    Re: Creating a Select All button for a multiple selection listbox with unknown values

     I think instead of this:

                XPathNodeIterator Cart = DataSources["Shopping Cart"].CreateNavigator().Select("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:Editor/pc:Person/pc:AccountId = xdXDocument:get-DOM()/my:myFields/my:RequestedBy/pc:Person/pc:AccountId]", NamespaceManager);

    You should just create another XPathNavigator for the main data source AccountId field and use that in your XPath filter:

                XPathNodeIterator Cart = DataSources["Shopping Cart"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:Editor/pc:Person/pc:AccountId ='", myvariablename, "']", NamespaceManager);

    You need to use a relative path here:

                    string reportName = Cart.Current.SelectSingleNode("d:Title", NamespaceManager).Value;

    Hilary Stoupa

  • 06-14-2013 12:38 PM In reply to

    • Omegacron
    • Not Ranked
    • Joined on 06-11-2013
    • Houston, TX
    • Posts 5

    Re: Creating a Select All button for a multiple selection listbox with unknown values

     Thanks for the reply Hilary - I think you're on the right track with the variable idea but I must be doing it incorrectly. Does the syntax here look correct to you? I'm getting the error "No overload for method 'Select' takes '4' arguments".

                // Define Main Datasource Objects
                XPathNavigator MainDS = MainDataSource.CreateNavigator();
                XPathNavigator Reports = MainDS.SelectSingleNode("//my:myFields/my:Reports", NamespaceManager);
                XPathNavigator Report = MainDS.SelectSingleNode("//my:myFields/my:Reports/my:Report", NamespaceManager);
                XPathNavigator CartUser = MainDS.SelectSingleNode("//my:myFields/my:RequestedBy/pc:Person/pc:AccountId", NamespaceManager);

                //Define Shopping Cart Objects
                XPathNavigator CartDS = DataSources["Shopping Cart"].CreateNavigator();
                XPathNavigator CartItems = CartDS.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW", NamespaceManager);
                XPathNavigator CartItem = CartDS.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title", NamespaceManager);
                XPathNodeIterator Cart = DataSources["Shopping Cart"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:Editor/pc:Person/pc:AccountId = '", CartUser, "']", NamespaceManager);
     

  • 06-14-2013 12:42 PM In reply to

    Re: Creating a Select All button for a multiple selection listbox with unknown values

     I'm sorry - my syntax was bad - I'd been writing concat statements instead of C#:

    XPathNodeIterator Cart = DataSources["Shopping Cart"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:Editor/pc:Person/pc:AccountId = '" +  CartUser.Value + "']", NamespaceManager);

    Hilary Stoupa

  • 06-14-2013 12:47 PM In reply to

    • Omegacron
    • Not Ranked
    • Joined on 06-11-2013
    • Houston, TX
    • Posts 5

    Re: Creating a Select All button for a multiple selection listbox with unknown values

     Thanks for the prompt reply - that did it! Now I just need to delete the blank first item and I'm home-free. I really appreciate the help!

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