Establish how the form was opened!! - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Establish how the form was opened!!

Last post 02-25-2010 02:34 AM by TerryB. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-24-2010 10:43 AM

    Establish how the form was opened!!

    Hi, I'm trying to establish how an infopath form was opened.

    Is it possible to establish if a form was opened using

    var fred = Application.XDocuments.Open("C:\\form1.xml");

    from another form or if it was opened direct by clicking on it? 




  • 02-24-2010 10:53 AM In reply to

    Re: Establish how the form was opened!!

    Hi --

    So you are trying to find out in your newly opened form whether it was opened from another form or not?

    I'd add a field or attribute to your target the form that you can set when you use code to open it. To try to make this more understandable, let's say I have two forms: Estimate and Work Order. I want to be able to click a button in my Estimate to open a Work Order. I also want to be able to just open the Work Order form on its own. I need to know if the Work Order was opened from the Estimate, or on its own. I'd add a field to Work Order called something dorky like "OpenedFromEstimate" and make it a boolean with a default value of false. Then, in my code for my Estimate button, I'd set the value of that field to true when I open the form from the Estimate.

    Does that make sense?

    Hilary Stoupa

  • 02-24-2010 11:09 AM In reply to

    Re: Establish how the form was opened!!

    Thanks for the quick response - I won' sleep tonight if I don't figure this out :-) 

    I'm not sure I fully understand!!

    node "OpenedFromEstimate" is part of the Work Order xsn DOM - how can I set this from the Estimate xsn DOM?

  • 02-24-2010 01:02 PM In reply to

    Re: Establish how the form was opened!!

    Perhaps it might help if I explain why I want to do this I want to be able to pass data from the first form to the second a little like how i think Application.XDocuments.NewFromSolutionWithData works (which I'm also trying to get working). However, if I can't I can use the fix of knowing how the form was opened. If I knew this, I could from the trigger form (Estimate) use web services to create an entry on a sharepoint list that the other form Work Order (if it was opened from Estimate) would read and pre-populate some fields. Cheers.
  • 02-24-2010 02:40 PM In reply to

    Re: Establish how the form was opened!!

    What object model are you using? 2003 or 2007? You can open a form from another and populate values into the newly opened form -- the code will vary depending on your object model...

    Hilary Stoupa

  • 02-24-2010 02:50 PM In reply to

    Re: Establish how the form was opened!!

    Here is a sample for the IP 2003 model -- this is C#, and I think you may be using script:

    //Create the new, blank workorder -- path changes according to your template location
    XDocument workOrder = thisApplication.XDocuments.NewFromSolution(@"C:\ComputerName\Folder\TemplateName.xsn");
    //Convert to IXMLDOMDocument2
    IXMLDOMDocument2 workOrderDOM = (IXMLDOMDocument2)workOrder.DOM;
    //Set the namespace -- changes according to YOUR form
    workOrderDOM.setProperty("SelectionNamespaces", "xmlns:my=\"\"");
    //Set a field -- xpath changes according to your target form
    workOrderDOM.selectSingleNode("/my:WorkOrders/my:EstimateId").text = "SomeValue";

    Search the forum for NewFromSolution to find other samples, I think there may be some script samples out there....

    Hilary Stoupa

  • 02-24-2010 03:04 PM In reply to

    Re: Establish how the form was opened!!

    Hilary - thanks I'll check this out in the morning and get back to you
  • 02-24-2010 03:06 PM In reply to

    Re: Establish how the form was opened!!

    2003 with jscript is my environment
  • 02-25-2010 02:34 AM In reply to

    Re: Establish how the form was opened!!

    Hilary, Brilliant! this will be a major enabler for us.

    It works in jscript with the following code:-

    function OpenNewFormandPassData::OnClick(eventObj)


    var fred = Application.XDocuments.NewFromSolution("C:\\MyForm.xsn"); // Open new form

    var source = XDocument.DOM.selectSingleNode("/my:myFields/my:test").text; // get local DOM node

    var MyFormDOM = fred.DOM; // set newly opened form var

    MyFormDOM.setProperty("SelectionNamespaces", "xmlns:my=\"\""); // sort out Namespace

    MyFormDOM.selectSingleNode("/my:myFields/my:employee").text = source; // set the new form node = node from local DOM


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