Pass parameters between two open forms - InfoPath Dev
in

InfoPath Dev

Pass parameters between two open forms

Last post 05-24-2012 05:36 AM by bblanke. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-16-2012 02:33 PM

    • bblanke
    • Top 500 Contributor
      Male
    • Joined on 11-12-2009
    • Milwaukee, WI
    • Posts 32

    Pass parameters between two open forms

    I have one form that will have a button that on click opens another another form that collects and provides some data that the user can accept or deny. If the user accepts the data, the data needs to be passed to the original form.

    The second form looks to a sharepoint form library [User Database] collects a list of names, it then looks out to it's own form library [Last Assigned User] to find the last name used, then outputs the next name. If the user accepts that name, the new name is stored in the form library [Last Assigned User] then passed back to the first form where the button was clicked.

    I know how to pass parameters within a url, but is there a way to pass parameter values between two open forms?

    Or do I need to create a new form in code that collects the data. If so, how can i submit a form in different schema than the originating form?

    Brandon Blanke
    Technical Analyst / Quad Graphics
  • 05-24-2012 01:23 AM In reply to

    Re: Pass parameters between two open forms

    Get rid of the second form and use a view on the 1st form... you can switch between views and all your data will be on one form
    Crazy-Ninja
    .Net Developer
  • 05-24-2012 05:36 AM In reply to

    • bblanke
    • Top 500 Contributor
      Male
    • Joined on 11-12-2009
    • Milwaukee, WI
    • Posts 32

    Re: Pass parameters between two open forms

    I found a solution by using the xml writer function and creating the second separate form within the code of the first form.
     
            private void buildForm(string firstChecker, string secondChecker, string firstCheckerName, string secondCheckerName, string location)
            {
                byte[] infoPathFormData = null;
     
                using (MemoryStream ms = new MemoryStream())
                {
                    using (XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8))
                    {
                        // Define the namespace for the form
                        string myNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-05-15T17:11:38";
     
                        writer.WriteStartDocument();
     
                        writer.WriteProcessingInstruction(
                            "mso-infoPathSolution",
                            "solutionVersion=\"1.0.0.12\" productVersion=\"12.0.0\" PIVersion=\"1.0.0.0\" href=\"http://teamsites.??.com/???/Templates/Conversion%20Checker%20Queue/forms/Conversion%20Checker%20Queue.xsn\" name=\"urn:schemas-microsoft-com:office:infopath:Conversion-Checker-Queue:-myXSD-2012-05-15T17-11-38\"");
                        writer.WriteProcessingInstruction(
                            "mso-application",
                            "progid=\"InfoPath.Document\" versionProgid=\"InfoPath.Document.2\"");
     
                        // Create the XML of the main data source of the form
                        writer.WriteStartElement("my", "myFields", myNamespace);
                        writer.WriteStartElement("my", "firstChecker", myNamespace);
                        writer.WriteString(firstChecker);
                        writer.WriteEndElement();
                        writer.WriteStartElement("my", "secondChecker", myNamespace);
                        writer.WriteString(secondChecker);
                        writer.WriteEndElement();
                        writer.WriteStartElement("my", "firstCheckerName", myNamespace);
                        writer.WriteString(firstCheckerName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("my", "secondCheckerName", myNamespace);
                        writer.WriteString(secondCheckerName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("my", "location", myNamespace);
                        writer.WriteString(location);
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        writer.WriteEndDocument();
                        writer.Flush();
                        writer.Close();
                    }
     
                    infoPathFormData = ms.GetBuffer();
                    ms.Close();
                }
     
                // Upload the newly created InfoPath form to SharePoint
                if (infoPathFormData != null && infoPathFormData.Length != 0)
                {
                    using (WebClient client = new WebClient())
                    {
                        // Set the credentials to be used for upload to SharePoint
                        client.Credentials = CredentialCache.DefaultCredentials;
     
                        string url = "http://teamsites.??.com/???/Templates/Conversion%20Checker%20Queue/" + System.DateTime.Now.ToString("yyyy-MM-ddTHH_mm_ss") + ".xml";
     
                        // Upload the newly created form to a SharePoint form library
                        client.UploadData(@url, "PUT", infoPathFormData);
     
                    }
                }
            }
     
    Brandon Blanke
    Technical Analyst / Quad Graphics
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.