Transfer Values from a SP GetListItems query to a InfoPath Repeating Table - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Transfer Values from a SP GetListItems query to a InfoPath Repeating Table

Last post 04-07-2010 08:03 AM by gally. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-06-2010 12:13 PM

    • gally
    • Not Ranked
    • Joined on 04-06-2010
    • Posts 5

    Transfer Values from a SP GetListItems query to a InfoPath Repeating Table

    I have a SharePoint 2007 list that I am attempting to query using the SP GetListItems web service and then write the returned values to a repeating table in InfoPath 2007.  I am very close to putting this altogether but am having trouble selecting the data I want in the query results.

    Thanks in advance!

    Here is my code:

     

            public void getListData()

            {

                WS_Lists.Lists myservice = new WS_Lists.Lists();

                myservice.Credentials = System.Net.CredentialCache.DefaultCredentials;

                myservice.Url = "http://portal-pd/pwa/plans/_vti_bin/Lists.asmx";

                try

                {

                    // Assign values to pass the GetListItems method

                    string listName = "{3DDECEF5-9660-4017-A099-9E4C24788439}";

                    string viewName = "{4751608D-6E7A-4F4F-BBCE-F0328F6A66E3}";

                    string rowLimit = "10000";

     

                    // Instantiate an XmlDocument object

                    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

                    System.Xml.XmlElement query = xmlDoc.CreateElement("Query");

                    System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");

                    System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

     

                    //Use CAML query

                    query.InnerXml = "<Where><Eq><FieldRef Name=\"Division\" />" +

                    "<Value Type=\"Text\">Atlanta</Value></Eq></Where>";

                    viewFields.InnerXml = "<FieldRef Name=\"Community\" /><FieldRef Name=\"ProjectDescription\" /><FieldRef Name=\"ProjectStatus\" />";

                    queryOptions.InnerXml = "";

     

                    System.Xml.XmlNode secDSNav = myservice.GetListItems(listName, viewName, query, viewFields, rowLimit, null, null);

     

                    System.Xml.XmlDocument xd = new System.Xml.XmlDocument();

     

                    xd.LoadXml(secDSNav.OuterXml);

     

                    XPathNavigator navigator = xd.CreateNavigator();

     

                    XPathNodeIterator rows = navigator.Select("/listitems/data/row", NamespaceManager);

     

                    while (rows.MoveNext())

                    {

                        string community = rows.Current.SelectSingleNode("@Community", NamespaceManager).Value;

                        string projectname = rows.Current.SelectSingleNode("@ProjectDescription", NamespaceManager).Value;

                        string projectstatus = rows.Current.SelectSingleNode("@ProjectStatus", NamespaceManager).Value;

     

                        // Add the item to the repeating table

                        AddItem(community, projectname, projectstatus);

                    }

     

                    // Remove the first empty item from the repeating table

                    DeleteFirstEmptyItem();

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.Message);

                }

            }

     

            private void AddItem(string community, string projectname, string projectstatus)

            {

                XmlDocument doc = new XmlDocument();

                XmlNode group = doc.CreateElement("group13",NamespaceManager.LookupNamespace("my"));

     

                XmlNode field = doc.CreateElement("field21",NamespaceManager.LookupNamespace("my"));

                XmlNode node = group.AppendChild(field);

                node.InnerText = community;

     

                field = doc.CreateElement("field22",NamespaceManager.LookupNamespace("my"));

                node = group.AppendChild(field);

                node.InnerText = projectname;

     

                field = doc.CreateElement("field23",NamespaceManager.LookupNamespace("my"));

                node = group.AppendChild(field);

                node.InnerText = projectstatus;

     

                doc.AppendChild(group);

     

                MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group12",NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

            }

     

            private void DeleteFirstEmptyItem()

            {

                XPathNavigator domNav = MainDataSource.CreateNavigator();

                XPathNavigator itemNav = domNav.SelectSingleNode("/my:myFields/my:group12/my:group13[1]",NamespaceManager);

     

                if (itemNav != null)

                    itemNav.DeleteSelf();

            }

           

    Filed under: , , ,
  • 04-07-2010 07:25 AM In reply to

    Re: Transfer Values from a SP GetListItems query to a InfoPath Repeating Table

    Hi Gally,

    Since this is such a common request (and since we have to sell something to pay for this free forum which costs us money), we developed qRules 2.1 which allows you to copy values from a SharePoint list into your form. If you want to pay for an hour of code support, we could look into it. If not, hopefully, someone else will review your code.

    Thanks for your understanding,

     

    Patrick Halstead
    Project Manager at Qdabra
  • 04-07-2010 08:03 AM In reply to

    • gally
    • Not Ranked
    • Joined on 04-06-2010
    • Posts 5

    Re: Transfer Values from a SP GetListItems query to a InfoPath Repeating Table

    Hi Patrick,

    Thanks for the quick reply!  I fully understand the need to pay the bills and appreciate you and the rest of the infopathdev team for creating a site like this.  I am aware that qRules has this ability to dynamically query a SharePoint list but my client requires additional functionality that is not included in the latest version of the software so I'm not able to use application.  Do you foresee the possibility in future releases of qRules in having it setup as an add-on set of features and controls to the InfoPath program rather than a collection of code that is injected into a form template?  I'm sure there are many others like me who would love to use the automation of the qRules software so long as it didn't limit their ability to add their own custom code when needed.Much appreciated,Gally
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.