Submit row of a repeating table to sharepoint based on criteria - InfoPath Dev
in

InfoPath Dev

Submit row of a repeating table to sharepoint based on criteria

Last post 06-26-2011 05:20 PM by Patrick Halstead. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-21-2011 01:28 PM

    • sz56ms
    • Not Ranked
    • Joined on 06-21-2011
    • Posts 1

    Submit row of a repeating table to sharepoint based on criteria

    I am a newbie to coding in Infopath.  All of my previous forms relied on rules to get the desired result.  I have used an example to submit all the data in a repeating table to sharepoint successfully.  The problem is, not all rows in the repeating table should be submitted.  I have added a dropdown list with YES or NO in the first column of the repeating table.  Any rows that have YES selected in the dropdown should be submitted to sharepoint.  This almost works correctly except the IF statement validates against the first row in the repeating table and uses that for the basis of whether or not to submit the entire list as compared to only the items selected within the list.  Basically, if my first row has NO selected, the list won't submit, if it has YES selected, it will submit, but still submit's the entire table, not specific rows.  I also need to ensure that there are no null fields before submitting.  Any help is greatly appreciated.

     

    public void CTRL499_15_Clicked(object sender, ClickedEventArgs e)
            {
               
                try
                {
                    // Get a reference to the form's XmlNamespaceManager object.
                    XmlNamespaceManager ns = this.NamespaceManager;

                    // Create a DataSource object for the MyContacts
                    // list data connection.
                    DataSource dsContacts = this.DataSources["NEW SCR SUBMITTED XML QUERY"];

                    // Create an XPathNavigator object for the MyContacts
                    // data connection.
                    XPathNavigator xnContacts = dsContacts.CreateNavigator();
                   
                    // Create an XPathNodeIterator object for the MyContacts
                    // data connection to enumerate the existing contacts.
                    XPathNodeIterator xiContacts = xnContacts.Select("/xml/rs:data/z:row", ns);

                    // Create a DataSource object for the Add List Item Template
                    // data connection.
                    DataSource dsCAML = this.DataSources["Add List Item Template2"];

                    // Create an XPathNavigator object for the
                    // Add List Item Template data connection.
                    // This is used to set the values in the CAML XML file.
                    XPathNavigator xnCAML = dsCAML.CreateNavigator();
                   
                    // Create a WebServiceConnection object for submitting
                    // to the Lists Web service data connection.
                    WebServiceConnection wsSubmit =(WebServiceConnection)this.DataConnections["SCR Web Service Submit"];

                    // Create an XPathNavigator object for the form's
                    // main data source.
                    XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();

                    // Create an XPathNodeIterator object for the new contacts.
                    XPathNodeIterator xiNewContacts = xnDoc.Select("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP", ns);
                   
                   
                   

                    while (xiNewContacts.MoveNext())
                    {
                        // Read only rows where the Changed dropdown list equals YES
                        if (xiNewContacts.Current.SelectSingleNode("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP/my:Changed", ns).Value == "YES")
                        {
       //Ensure that the Submitter field is not blank.
                            if (xiNewContacts.Current.SelectSingleNode("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP/my:Submitter", ns).Value != "")

                           
                            // Set the values in the Add List Item Template
                            // XML file using the values in the new row.
                           
                            xnCAML.SelectSingleNode(
                               "/Batch/Method/Field[@Name='Project_Number']", ns)
                               .SetValue(xiNewContacts.Current.SelectSingleNode(
                               "my:Project_Number", ns).Value);
                            xnCAML.SelectSingleNode(
                               "/Batch/Method/Field[@Name='Submitter']", ns)
                               .SetValue(xiNewContacts.Current.SelectSingleNode(
                               "my:Submitter", ns).Value);
                            xnCAML.SelectSingleNode(
                               "/Batch/Method/Field[@Name='Place']", ns)
                               .SetValue(xiNewContacts.Current.SelectSingleNode(
                               "my:Place", ns).Value);
                            xnCAML.SelectSingleNode(
                               "/Batch/Method/Field[@Name='Site']", ns)
                               .SetValue(xiNewContacts.Current.SelectSingleNode(
                               "my:Site", ns).Value);
                            xnCAML.SelectSingleNode(
                               "/Batch/Method/Field[@Name='Location']", ns)
                               .SetValue(xiNewContacts.Current.SelectSingleNode(
                               "my:Location", ns).Value);
                          
                           

                            // Set the value of Cmd attribute to "New".
                            xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns)
                               .SetValue("New");

                            // Submit the new row.
                            wsSubmit.Execute();
                           
                           
                        }
                    }
                        }
                   
               

                catch (Exception ex)
                {
                    MessageBox.Show("The following error occurred: " + ex.Message);
                    throw;
                }

             }

  • 06-26-2011 05:20 PM In reply to

    Re: Submit row of a repeating table to sharepoint based on criteria

    Hi Sz56MS,

    qRules can do this without code. you are thinking -- no no no, I don't want a third-party plug-in, I want to write code cuz I'm a VB developer and I deserve to do C#....

    Well, fine, but please keep in mind that we developed qRules so we could stop answering the thousands of posts in this forum regarding all of the gaps in the wonderful InfoPath and SharePoint story.

    So, if you can use the free trial to accomplish your work, and you are willing to give us a nice little testimonial (a few sentences) we'll give you the extra special deal.

    Juist let us know...

    :)

    PS> or, we could help you write code but that'll cost ya...

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.