Wouldn’t it be nice to open an InfoPath form from another form, and “jump” to a particular row in the database that is being referenced?

That was my question, and it took some questioning, searching, etc to get the answer. (Thanks to http://www.infopathdev.com, and http://msdn.microsoft.com)

So here it goes, I have a form that I query and get the results, and then I want to jump to another form based on my results.

I created a button, and then edited the button.

Here is the actual code, in which I will comment on it after:

function OpenDetail::OnClick(eventObj)
{
//Get the local file path
var sFormPath = “”;
var sUri = XDocument.Solution.URI;
var i = sUri.lastIndexOf(””);
if(-1 == i)
i = sUri.lastIndexOf(”/”);
sFormPath = sUri.substring(0, i + 1);

//Get the Parent ID form this form
var param1=XDocument.DOM.selectSingleNode(”/dfs:myFields/dfs:dataFields/d:ContactInfo/@ID”).text;

//Start the application
var oApp = new ActiveXObject(”InfoPath.Application”);

//Open an InfoPath document from the published template
var oXDocumentCollection = oApp.XDocuments;
var oXDocument = oXDocumentCollection.NewFromSolution(sFormPath+”detail.xsn”);

// Get pointers to the target fields
var oID = oXDocument.DOM.selectSingleNode(”//@parentid”);

//Update the fields
oID.text = param1;

oXDocument.Query();
}

The first part gets the local directoy (assuming that both forms are located in the same directory.
The second part grabs the data from the ’parent’ form that is going to be used to key the second form.
{The rest of the code’s comments explain what is going on.}

Once that the variable is filled, then we can run the Query() function to return the data.

The issues that I am having right now is that when you open up the new form, you get 3 security warning messages, so I am looking at how to get rid of those dialog boxes.