SharePoint drop-down list box sorting - InfoPath Dev
in

InfoPath Dev

SharePoint drop-down list box sorting

Last post 10-04-2012 10:34 PM by Niyaz. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-16-2008 08:03 AM

    SharePoint drop-down list box sorting

    I have successfully created a binding on a drop-down list box to a SharePoint list.  When I open the form in InfoPath, the drop-down list box is sorted correctly based on the default view of the SharePoint list; however when I open the form using SharePoint's form service, the list box is not sorted correctly.  I can't seem to figure out how to sort this list.  Could someone point me in the right direction?
  • 12-16-2008 08:45 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: SharePoint drop-down list box sorting

    Hello,

    We can sort using the below code,

    ArrayList sortValues = new ArrayList();

    foreach(IXMLDOMNode repeatingNode in repeatingNodes)

    {

    sortValues.Add(repeatingNode.xml);

    }

    sortValues.Sort();

    Using above code it will sort by order and we have to replace old repeating section nodes with new repeating section nodes.

    Here is ‘repeatingNodes' is SharePoint dropdown list values.

    You can use this when you want to sort those values in OnLoad or OnClick event of button.

  • 12-16-2008 10:03 AM In reply to

    Re: SharePoint drop-down list box sorting

     I'm still pretty new to InfoPath so I may need a bit more info.  Does this code go in the OnLoad event handler for the form or the list box control?  I can't seem to find either for the form or the control.

  • 12-17-2008 05:27 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: SharePoint drop-down list box sorting

    Hello,

    We can add the button to your form. Double click on your button,

    1. If you have solution (.sln) for this form then you have click on ‘Edit Form code' button in Button Properties to go formcode.cs file.

    2. If you do not have solution file then you have to follow these below steps,

    a. Tools -> Form Options -> Programming.

    b. Select ‘Jscript' in ‘Form template code language' dropdown.

    c. Click on ‘OK' button.

    3. Then again follow the above 1st step to write the code.

    You will get ‘Onclick' event for your button and copy the below code into that event to get the sorting order for dropdown values,

    C#:

    XPathNavigator navigator = this.MainDataSource.CreateNavigator();

    XPathNodeIterator repeatingNodes = navigator.SelectChildren("XPath of your field", "Namespace of your form");

    ArrayList sortValues = new ArrayList();

    foreach(XMLNode repeatingNode in repeatingNodes)

    {

    sortValues.Add(repeatingNode.xml);

    }

    sortValues.Sort();

    BLOCKED SCRIPT

    var thisDOM = window.external.Window.XDocument;

    var repeatingNodes = thisDOM .selectNodes("XPath of your field");

    var sortValues = new Array();

    foreach(var repeatingNode in repeatingNodes)

    {

    sortValues.Add(repeatingNode.xml);

    }

    sortValues.Sort("SortFunctionName");

  • 12-17-2008 06:52 AM In reply to

    Re: SharePoint drop-down list box sorting

    Thanks for the information, but this does not account for other nuances of the default view in SharePoint.  The view in SharePoint also does some filtering that does not seem to be reproduced in the form service on MOSS.  Personally I think its a bug or a gross oversight by Microsoft that the SharePoint dataconnection does not properly pull from a view or have the ability to specify the view.

    I actually found an easier way of handling this issue that takes into account the actual view in SharePoint without having to add any unnecessary code.  I followed the steps outlined in this article to use the view of the SharePoint list.

    First get the URL:

    1. Navigate to the SharePoint site that contains the list, for example: http://contoso/sites/sales/Sales%20Contacts/Forms/AllItems.aspx
    2. Edit the list settings
    3. Copy the List={GUID} portion of the URL and paste this into a buffer like a Notepad window
    4. In Notepad, create the following URL (the blue portion us taken from the step 1 URL, and the red portion must be added
    http://contoso/sites/sales/_vti_bin/owssvr.dll?Cmd=Display&List={GUID}&XMLDATA=TRUE

    During creation of the data connection, do not include the file in the form template, as it should be dynamically generated from the SharePoint list.  This will return an xml file that can be used in an XML file data connection, as if it came from a file system.  After this, you can use the URL as the location of an XML data file when creating a data connection.

  • 10-04-2012 10:34 PM In reply to

    • Niyaz
    • Not Ranked
    • Joined on 12-19-2011
    • Posts 4

    Re: SharePoint drop-down list box sorting

    Hi Dishmael

    Thanks for sharing this process, could you please share your views of below Query.

    As mentioned in the thread the link returns the XML file and we save this file in file system and during data connection we used to provide the XML path, but how this XML is update. Suppose if I would like to update the SP lookup list how this XML will update?

     Please suggest. Let me know for any concerns.

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