Passing Parameters - InfoPath Dev
in

InfoPath Dev

Passing Parameters

Last post 04-23-2010 04:55 PM by Lawson. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 04-20-2010 04:54 PM

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Passing Parameters

    I have an InfoPath 2003 form with C# code. I have seven text boxes that users will enter different types of data into.

    I am trying to create a button that will open a new from and place the data from the text boxes in the first form into the text boxes of the new form.

    Does anybody know how to do this in IP 2003?

     Thanks,

    -Lawson

  • 04-20-2010 11:42 PM In reply to

    check this.

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 04-21-2010 08:36 AM In reply to

    Hey, Lawson:

    Here's what I've used in the past:

    //Create the new form
    XDocument newForm = thisApplication.XDocuments.NewFromSolution(@"C:\Users\Lawson\Desktop\Switch View.xsn");
     
    //Convert to IXMLDOMDocument2
    IXMLDOMDocument2 newFormDom = (IXMLDOMDocument2)newForm.DOM;
     
    //Set the namespace (correct for the appropriate namespace for YOUR template)
    newFormDom.setProperty("SelectionNamespaces", "xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-06T22:11:15\"");
     
     
    //fill in new form fields         
    newFormDom.selectSingleNode("/my:myFields/my:WhateverTheRealXpathIs").text = "Test";

    You'll want to update the namespace. You can set fields in your new form to values from your current form rather than the text value I show.

    Hilary Stoupa

  • 04-22-2010 05:15 AM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Hey Hilary,

    Thanks for your help. I won't have a chance to run this until later on tonight.

    I have one question about the correct namespace.

    Where can I find the correct namespace for my template?

    Thanks,

    -Lawson

  • 04-22-2010 08:40 AM In reply to

    Save your target form (the one you want to open in your code) as source files. Open up the template.xml in a text editor and look for the namespace declaration -- if you created the schema while building the template, it is probably the "my" namespace and looks like this:

    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-12T19:46:43"

    You want the bit in quotes.

    Hilary Stoupa

  • 04-22-2010 10:49 AM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Thanks Hilary, I greatly appreciate it.

     

    I have just one more question. I can probably figure this out when I run this code later tonight, but I’m just curious.

     

    In the last line of code:

    newFormDom.selectSingleNode("/my:myFields/my:WhateverTheRealXpathIs").text = "Test";

     

     Is "my:myFields/my:WhateverTheRealXpathIs" the Xpath for the new form, and "Test" is the Xpath of the original form or the form that is giving the ddata? or  

    Is “test” a local variable with the data?

     

    Thanks,-Lawson

     

  • 04-22-2010 06:30 PM In reply to

    No, "Test" is just a string that I was showing as a sample. You'd want to create a string variable with data from your original form (thisXDocument.DOM.selectSingleNode("xpathToNode") etc). And yes, the made up XPath in the newFormDom's selectSingleNode method would be to the field you wish to set.

    Hilary Stoupa

  • 04-23-2010 03:53 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    You're Awesome Hilary! :)

    Just ran the code, and it works well.

    -Lawson

  • 04-23-2010 04:15 PM In reply to

    Glad to hear it! Have a great weekend!

    Hilary Stoupa

  • 04-23-2010 04:21 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Hilary,

    Thank you for all of your help, just one more question...

    Three of the fields in the form are drop down boxes. I am using the following code to pass the data:

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field5").text = "ContractType";

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field6").text = "Option";

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field7").text = "ContractingProcedure";

    However, the new form drop down boxes are blank.

    Do you have any suggestions?

    Thanks,

    -Lawson

  • 04-23-2010 04:55 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Hilary, figured it out with the following code:

     

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field5").text = ContractType;

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field6").text = Option;

    newFormDom.selectSingleNode("/my:myFields/my:group1/my:field7").text = ContractingProcedure;

     

    Thanks again! :)

    Have a great weekend!

    -Lawson

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