Submitting a single email with values of a repeating table (Master/Detail section) - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Submitting a single email with values of a repeating table (Master/Detail section)

Last post 06-23-2011 04:24 PM by buck_murdock. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 06-23-2011 04:24 PM

    Submitting a single email with values of a repeating table (Master/Detail section)

    I have a form built with InfoPath 2007 and C# code.  This form has a Master/Detail Section for initiating requests regarding office moves in our location.  The requestor can enter in an employee name and all the pertinent information regarding their current location and the new location, and then add a new person and fill out that information as well, and keep entering in information for all the users that are moving.

    Check out the screen shot to see the repeating section information.

    I've followed this article so that it will submit each employees information as a seperate line item in a sharepoint list.  http://www.bizsupportonline.net/infopath2007/how-to-submit-items-rows-repeating-table-infopath-sharepoint-list.htm

    Everything submits to the sharepoint side just fine, however, the powers that be here at work would like this to also be entered into our archaic ticketing system.  This system enters tickets via email and I'd like to be able to gather the data from the repeating fields and submit it to this email address in a single email while still keeping the seperate line items in the list.

    I've found a few posts on this site and other sites, and I've got the email portion working, however it sends a seperate email for each repeating section.  Is there a way to just have it send one email with all the information in there?  i saw a post here about using the XPathNodeIterator but i'm not savy enough with the code to understand how to use it, i already have the XPathNodeIterator in the code for submitting the list items, how can i piggy back off that to submit a single email with the pertinent values.

     You have all been a great help in the past and helped me really expand my InfoPath expertise, and i'm hoping you can help me get over this hump as well.

     Thanks in Advanced!!!!!!!

     If it helps here is my code so far, it's kind of long because there are a lot of fields so sorry...

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using System.Windows.Forms;
    using mshtml;

    namespace EmployeeForm
    {
        public partial class FormCode
        {
            // Member variables are not supported in browser-enabled forms.
            // Instead, write and read these values from the FormState
            // dictionary using code such as the following:
            //
            // private object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft Office InfoPath.
            // It can be modified using Microsoft Office InfoPath.
            public void InternalStartup()
            {
                ((ButtonEvent)EventManager.ControlEvents["Submit"]).Clicked += new ClickedEventHandler(Submit_Clicked);
            }

            public void Submit_Clicked(object sender, ClickedEventArgs e)
            {
               
                // Delete all Method nodes from the CAML Batch XML
                XPathNavigator secDSNav = DataSources["CustomListCAML"].CreateNavigator();
                XPathNodeIterator iter = secDSNav.Select("/Batch/Method");
                int methodNodesCount = iter.Count;

                XPathNavigator firstMethodNav =
                   secDSNav.SelectSingleNode("/Batch/Method[1]",
                   NamespaceManager);
                XPathNavigator lastMethodNav =
                  secDSNav.SelectSingleNode("/Batch/Method[" + methodNodesCount.ToString() + "]",
                  NamespaceManager);

                firstMethodNav.DeleteRange(lastMethodNav);

                // Retrieve the rows of the repeating table
                XPathNavigator root = MainDataSource.CreateNavigator();
                XPathNodeIterator employeeInfoDetail = root.Select(
                  "/my:employeeForm/my:employeeInfo/my:employeeInfoDetail", NamespaceManager);

                //Retrieve the Non-Repeating Form Fields
                string requestorName = root.SelectSingleNode("/my:employeeForm/my:RequestInfo/my:requestorName",
            NamespaceManager).Value;
                string requestorDept = root.SelectSingleNode("/my:employeeForm/my:RequestInfo/my:requestorDept",
            NamespaceManager).Value;
                string requestorEmail = root.SelectSingleNode("/my:employeeForm/my:RequestInfo/my:requestorEmail",
            NamespaceManager).Value;
                string requestorPhone = root.SelectSingleNode("/my:employeeForm/my:RequestInfo/my:requestorPhone",
            NamespaceManager).Value;
                string requestType = root.SelectSingleNode("/my:employeeForm/my:RequestInfo/my:requestType",
            NamespaceManager).Value;

                // Loop through the rows of the repeating table
                // and construct the CAML Batch XML
                int counter = 1;
                while (employeeInfoDetail.MoveNext())
                {
                    // Retrieve the Repeating Form Values
                    string title = employeeInfoDetail.Current.SelectSingleNode(
                      "my:title", NamespaceManager).Value;
                    string employmentType = employeeInfoDetail.Current.SelectSingleNode(
                        "my:employmentType", NamespaceManager).Value;
                    string firstName = employeeInfoDetail.Current.SelectSingleNode(
                        "my:firstName", NamespaceManager).Value;
                    string lastName = employeeInfoDetail.Current.SelectSingleNode(
                        "my:lastName", NamespaceManager).Value;
                    string employeeName = employeeInfoDetail.Current.SelectSingleNode(
                        "my:employeeName", NamespaceManager).Value;
                    string directorate = employeeInfoDetail.Current.SelectSingleNode(
                        "my:directorate", NamespaceManager).Value;
                    string department = employeeInfoDetail.Current.SelectSingleNode(
                        "my:department", NamespaceManager).Value;
                    string newDirectorate = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newDirectorate", NamespaceManager).Value;
                    string newDepartment = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newDepartment", NamespaceManager).Value;
                    string orgCode = employeeInfoDetail.Current.SelectSingleNode(
                        "my:orgCode", NamespaceManager).Value;
                    string newOrgCode = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newOrgCode", NamespaceManager).Value;
                    string chargeAccount = employeeInfoDetail.Current.SelectSingleNode(
                        "my:chargeAccount", NamespaceManager).Value;
                    string building = employeeInfoDetail.Current.SelectSingleNode(
                        "my:building", NamespaceManager).Value;
                    string room = employeeInfoDetail.Current.SelectSingleNode(
                        "my:room", NamespaceManager).Value;
                    string newBuilding = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newBuilding", NamespaceManager).Value;
                    string newRoom = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newRoom", NamespaceManager).Value;
                    string mailstop = employeeInfoDetail.Current.SelectSingleNode(
                        "my:mailstop", NamespaceManager).Value;
                    string newMailstop = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newMailstop", NamespaceManager).Value;
                    string extension = employeeInfoDetail.Current.SelectSingleNode(
                        "my:extension", NamespaceManager).Value;
                    string newExtension = employeeInfoDetail.Current.SelectSingleNode(
                        "my:newExtension", NamespaceManager).Value;
                    string faxLine = employeeInfoDetail.Current.SelectSingleNode(
                        "my:faxLine", NamespaceManager).Value;
                    string internationalLine = employeeInfoDetail.Current.SelectSingleNode(
                        "my:internationalLine", NamespaceManager).Value;
                    string confLine = employeeInfoDetail.Current.SelectSingleNode(
                        "my:confLine", NamespaceManager).Value;
                    string multiPhone = employeeInfoDetail.Current.SelectSingleNode(
                        "my:multiPhone", NamespaceManager).Value;
                    string startDate = employeeInfoDetail.Current.SelectSingleNode(
                        "my:startDate", NamespaceManager).Value;
                    string endDate = employeeInfoDetail.Current.SelectSingleNode(
                        "my:endDate", NamespaceManager).Value;
                    string moveDate = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveDate", NamespaceManager).Value;
                    string wave = employeeInfoDetail.Current.SelectSingleNode(
                        "my:wave", NamespaceManager).Value;
                    string desktop = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:desktop", NamespaceManager).Value;
                    string laptop = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:laptop", NamespaceManager).Value;
                    string display = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:display", NamespaceManager).Value;
                    string printer = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:printer", NamespaceManager).Value;
                    string keyboardTray = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:keyboardTray", NamespaceManager).Value;
                    string pcNumbers = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:pcNumbers", NamespaceManager).Value;
                    string networkConnections = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moveEquipment/my:networkConnections", NamespaceManager).Value;
                    string provideComputer = employeeInfoDetail.Current.SelectSingleNode(
                        "my:provideComputer", NamespaceManager).Value;
                    string supervisor = employeeInfoDetail.Current.SelectSingleNode(
                        "my:gpContactSelector/my:Person/my:DisplayName", NamespaceManager).Value;
                    string computerType = employeeInfoDetail.Current.SelectSingleNode(
                        "my:computerOptions/my:computerType", NamespaceManager).Value;
                    string desktopSelection = employeeInfoDetail.Current.SelectSingleNode(
                        "my:computerOptions/my:desktopSelection", NamespaceManager).Value;
                    string laptopSelection = employeeInfoDetail.Current.SelectSingleNode(
                        "my:computerOptions/my:laptopSelection", NamespaceManager).Value;
                    string otherSelection = employeeInfoDetail.Current.SelectSingleNode(
                        "my:computerOptions/my:otherSelection", NamespaceManager).Value;
                    string displaySelection = employeeInfoDetail.Current.SelectSingleNode(
                        "my:computerOptions/my:displaySelection", NamespaceManager).Value;
                    string comments = employeeInfoDetail.Current.SelectSingleNode(
                        "my:comments", NamespaceManager).Value;
                    string moverNotes = employeeInfoDetail.Current.SelectSingleNode(
                        "my:moverNotes", NamespaceManager).Value;
                    string newSupervisor = employeeInfoDetail.Current.SelectSingleNode(
                        "my:transferInfo/my:gpContactSelector/my:Person/my:DisplayName", NamespaceManager).Value;
                   
                    // Add an item to the CAML Batch XML
                    AddMethodNode(counter, title, requestorName, requestorDept, requestorEmail, requestorPhone, requestType, employmentType, firstName, lastName, employeeName, directorate, department, newDirectorate, newDepartment, orgCode, newOrgCode, chargeAccount, building, room, newBuilding, newRoom, mailstop, newMailstop, extension, newExtension, faxLine, internationalLine, confLine, multiPhone, startDate, endDate, moveDate, wave, desktop, laptop, display, printer, keyboardTray, pcNumbers, networkConnections, provideComputer, supervisor, computerType, desktopSelection, laptopSelection, otherSelection, displaySelection, comments, moverNotes, newSupervisor);

                    // Increment the counter
                    counter++;

                    // Set the properties for the email
                    string toAddress = "tadams@slac.stanford.edu";
                    EmailSubmitConnection emailConn =
                     (EmailSubmitConnection)DataConnections["Email Submit"];
                    emailConn.To.SetStringValue(toAddress);
                    emailConn.Subject.SetStringValue("Employee Move Request submitted by - " + requestorName);
                    emailConn.Introduction = "This email was generated by code." + "\r\n" + employeeName;
                    emailConn.EmailAttachmentType = EmailAttachmentType.None;

                    // Send the email
                    emailConn.Execute();

                    // Indicate success
                    //e.CancelableArgs.Cancel = false;

                 }

                // Submit the rows to the Lists web service to update the custom list
                DataConnections["CustomListItemsSubmit"].Execute();
                Application.Quit();

            }
            private void AddMethodNode(int id, string title, string requestorName, string requestorDept, string requestorEmail, string requestorPhone, string requestType, string employmentType, string firstName, string lastName, string employeeName, string directorate, string department, string newDirectorate, string newDepartment, string orgCode, string newOrgCode, string chargeAccount, string building, string room, string newBuilding, string newRoom, string mailstop, string newMailstop, string extension, string newExtension, string faxLine, string internationalLine, string confLine, string multiPhone, string startDate, string endDate, string moveDate, string wave, string desktop, string laptop, string display, string printer, string keyboardTray, string pcNumbers, string networkConnections, string provideComputer, string supervisor, string computerType, string desktopSelection, string laptopSelection, string otherSelection, string displaySelection, string comments, string moverNotes, string newSupervisor)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendFormat("<Method ID=\"{0}\" Cmd=\"New\">", id.ToString());
                sb.AppendFormat("<Field Name=\"Title\">{0}</Field>", title);
                sb.AppendFormat("<Field Name=\"requestorName\">{0}</Field>", requestorName);
                sb.AppendFormat("<Field Name=\"requestorDept\">{0}</Field>", requestorDept);
                sb.AppendFormat("<Field Name=\"requestorEmail\">{0}</Field>", requestorEmail);
                sb.AppendFormat("<Field Name=\"requestorPhone\">{0}</Field>", requestorPhone);
                sb.AppendFormat("<Field Name=\"requestType\">{0}</Field>", requestType);
                sb.AppendFormat("<Field Name=\"employmentType\">{0}</Field>", employmentType);
                sb.AppendFormat("<Field Name=\"firstName\">{0}</Field>", firstName);
                sb.AppendFormat("<Field Name=\"lastName\">{0}</Field>", lastName);
                sb.AppendFormat("<Field Name=\"employeeName\">{0}</Field>", employeeName);
                sb.AppendFormat("<Field Name=\"directorate\">{0}</Field>", directorate);
                sb.AppendFormat("<Field Name=\"department\">{0}</Field>", department);
                sb.AppendFormat("<Field Name=\"newDirectorate\">{0}</Field>", newDirectorate);
                sb.AppendFormat("<Field Name=\"newDepartment\">{0}</Field>", newDepartment);
                sb.AppendFormat("<Field Name=\"orgCode\">{0}</Field>", orgCode);
                sb.AppendFormat("<Field Name=\"newOrgCode\">{0}</Field>", newOrgCode);
                sb.AppendFormat("<Field Name=\"chargeAccount\">{0}</Field>", chargeAccount);
                sb.AppendFormat("<Field Name=\"building\">{0}</Field>", building);
                sb.AppendFormat("<Field Name=\"room\">{0}</Field>", room);
                sb.AppendFormat("<Field Name=\"newBuilding\">{0}</Field>", newBuilding);
                sb.AppendFormat("<Field Name=\"newRoom\">{0}</Field>", newRoom);
                sb.AppendFormat("<Field Name=\"mailstop\">{0}</Field>", mailstop);
                sb.AppendFormat("<Field Name=\"newMailstop\">{0}</Field>", newMailstop);
                sb.AppendFormat("<Field Name=\"extension\">{0}</Field>", extension);
                sb.AppendFormat("<Field Name=\"newExtension\">{0}</Field>", newExtension);
                sb.AppendFormat("<Field Name=\"faxLine\">{0}</Field>", faxLine);
                sb.AppendFormat("<Field Name=\"internationalLine\">{0}</Field>", internationalLine);
                sb.AppendFormat("<Field Name=\"confLine\">{0}</Field>", confLine);
                sb.AppendFormat("<Field Name=\"multiPhone\">{0}</Field>", multiPhone);
                sb.AppendFormat("<Field Name=\"startDate\">{0}</Field>", startDate);
                sb.AppendFormat("<Field Name=\"endDate\">{0}</Field>", endDate);
                sb.AppendFormat("<Field Name=\"moveDate\">{0}</Field>", moveDate);
                sb.AppendFormat("<Field Name=\"wave\">{0}</Field>", wave);
                sb.AppendFormat("<Field Name=\"desktop\">{0}</Field>", desktop);
                sb.AppendFormat("<Field Name=\"laptop\">{0}</Field>", laptop);
                sb.AppendFormat("<Field Name=\"display\">{0}</Field>", display);
                sb.AppendFormat("<Field Name=\"printer\">{0}</Field>", printer);
                sb.AppendFormat("<Field Name=\"keyboardTray\">{0}</Field>", keyboardTray);
                sb.AppendFormat("<Field Name=\"pcNumbers\">{0}</Field>", pcNumbers);
                sb.AppendFormat("<Field Name=\"networkConnections\">{0}</Field>", networkConnections);
                sb.AppendFormat("<Field Name=\"provideComputer\">{0}</Field>", provideComputer);
                sb.AppendFormat("<Field Name=\"supervisor\">{0}</Field>", supervisor);
                sb.AppendFormat("<Field Name=\"computerType\">{0}</Field>", computerType);
                sb.AppendFormat("<Field Name=\"desktopSelection\">{0}</Field>", desktopSelection);
                sb.AppendFormat("<Field Name=\"laptopSelection\">{0}</Field>", laptopSelection);
                sb.AppendFormat("<Field Name=\"otherSelection\">{0}</Field>", otherSelection);
                sb.AppendFormat("<Field Name=\"displaySelection\">{0}</Field>", displaySelection);
                sb.AppendFormat("<Field Name=\"comments\">{0}</Field>", comments);
                sb.AppendFormat("<Field Name=\"moverNotes\">{0}</Field>", moverNotes);
                sb.AppendFormat("<Field Name=\"newSupervisor\">{0}</Field>", newSupervisor);
                sb.AppendFormat("</Method>");

                XmlDocument methodXML = new XmlDocument();
                methodXML.LoadXml(sb.ToString());

                XPathNavigator secDSNav = DataSources["CustomListCAML"].CreateNavigator();
                XPathNavigator batchNav = secDSNav.SelectSingleNode("/Batch", NamespaceManager);
                batchNav.AppendChild(methodXML.DocumentElement.CreateNavigator());
            }
            }
          }


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