Exchanging data between modules

A

Andrea V.F.

Into an infopath form I need to call another module and pass to this
module an integer value. How could I do this (if this is possible)??


Thanks, Andrea.
 
A

Andrea V.F.

I mean another "xsn" file.

For Example:
in file a.xsn there is a button. When i click this button it opens the
b.xsn file and I want to pass a value to b.
 
H

Henning Krause [MVP - Exhange]

Hello,

you can do this from within the script file (Note: This example is in C#,
but you can use JScript in a similar way).

// The url of the second form, must be absolute (i.e. c:\myforms\form.xsn).
This example opens a form that lies in the same directory as the source form
url = XDocument.Solution.URI;
url =
HttpUtility.UrlDecode(url.Substring(url.IndexOf("://")+4)).Replace("/",
"\\");
url = Path.Combine(Path.GetDirectoryName(url), "News Template.xsn");

// Open a new instance of the second xsn
doc = Application.XDocuments.NewFromSolution(url);

// Get the Datasource of the second form. Note: In Jscript you won't need
the casting to the IXMLDOMDocument2
dom = (IXMLDOMDocument2) doc.DOM;
// Set the namespace to the one used within the second document
dom.setProperty("SelectionNamespaces",
"xmlns:my=\http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-05T13:36:27\");

// Set the value
doc.DOM.selectSingleNode("//my:integervalue").text = 42;

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
 
A

Andrea V.F.

I received an error in the code because I don't have HttpUtility in
JScript. So I assign to the variable "url" the path by hand
(url="C:\foo\module.xsn")

All works, but when I try to set the integer value I receive an error:
" doc.DOM.selectSingleNode(...) is null or is not an object". Using the
debug I've found that selectSingleNode returns "Null".

any suggestion?

Thanks for the help Henning.
 
H

Henning Krause [MVP - Exhange]

Hello,

as I said, the XPath must be valid, and the namespace must match the
namespace of the xsn you are opening.

If selectSingleNode is null, than no node that matches your XPath expression
was found. If all fails, take your debugger and look at the doc.DOM.xml
value. That contains the entire XML file, including the namespace
declarations.

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
 
A

Andrea V.F.

This is the doc.DOM.xml value:

<?xml version=\"1.0\"?><?mso-infoPathSolution
solutionVersion=\"1.0.0.2\" productVersion=\"11.0.6357\"
PIVersion=\"1.0.0.0\" href=\"file:///C:\jirapa\test.xsn\"
name=\"urn:schemas-microsoft-com:eek:ffice:infopath:test:-myXSD-2005-06-08T09-49-50\"
?><?mso-application progid=\"InfoPath.Document\"?><my:campiPersonali
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-08T09:49:50\"
xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"
xml:lang=\"it\">
<my:Campo></my:Campo>
</my:campiPersonali>

I think the XPath is correct. I use:

doc.DOM.selectSingleNode("//my:Campo").text = 42;
 
H

Henning Krause [MVP - Exhange]

Hello,

have you registered the "my" namespace correctly?

In your case, try the following
// Set the namespace to the one used within the second document

doc.DOM.setProperty("SelectionNamespaces",
"xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-08T09:49:50\");
doc.DOM.selectSingleNode("//my:Campu");

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
 
A

Andrea V.F.

Yes. I paste the whole of the OnClick event for the button:

function CTRL35_6::OnClick(eventObj)
{
// Scrivere il codice qui
debugger;
// The url of the second form, must be absolute (i.e.
c:\myforms\form.xsn).
//This example opens a form that lies in the same directory as the
source form
//url = XDocument.Solution.URI;
//url = url.Substring(url.IndexOf("://")+4).Replace("/", "\\");
//url = Path.Combine(Path.GetDirectoryName(url), "Test.xsn");
url="c:\\jirapa\\test.xsn"
// Open a new instance of the second xsn
doc = Application.XDocuments.NewFromSolution(url);

// Get the Datasource of the second form. Note: In Jscript you won't
need the casting to the IXMLDOMDocument2
dom = doc.DOM;
// Set the namespace to the one used within the second document
dom.setProperty("SelectionNamespaces",
"xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-05T13:36:27\"");

// Set the value
doc.DOM.selectSingleNode("//my:Campo").text = 42;

}
 
H

Henning Krause [MVP - Exhange]

A

Andrea V.F.

It Works :) Thanks Thanks and again Thanks.

You Solved Me a Lot of Problems.

Andrea.
 
Top