OnSaveRequest Problem

L

Luke Slotwinski

I am having a problem creating an onsaverequest function.
I am not sure how to define a field for the request to define in the save
function.
My Data Source is organized in a folder called Childrens, and the fields are
last, dhmrn, and cdate I want to pull the data that was entered by the user
and use those three fields to generate a filename. however... i do not know
how to define the XDocument.DOM.selectSingleNode (...) Im do not understand
what the syntax inside the ( ) should be.

Code reads :
function XDocument::OnSaveRequest(eventObj)
{
var last1 = XDocument.DOM.selectSingleNode ("//my:last").text;
var dhmrn1 = XDocument.DOM.selectSingleNode ("/:dhmrn").text;
var cdate1 = XDocument.DOM.selectSingleNode ("/:cdate").text;
if (XDocument.IsNew == true || eventObj.IsSaveAs == false)
{
if (eventObj.IsSaveAs == true)
{
XDocument.UI.SetSaveAsDialogLocation("T:\\Lab Micro-Sero
Proc\micro_sendouts\childrens");
XDocument.UI.SetSaveAsDialogFileName(last1 + "_" + dhmrn1 + "_"
+ cdate1);
}
eventObj.IsCancelled = eventObj.PerformSaveOperation();
eventObj.ReturnStatus = true;
}
else
{
XDocument.UI.Alert("The 'Save As' functionality is disabled for
forms that are not new.");
}


Thanks
 
S

S.Y.M. Wong-A-Ton

It is called an XPath expression. It is a syntax to be able to retrieve an
XML node in an XML document. You can read more about it here
http://www.w3.org/TR/xpath and here
http://www.w3schools.com/xpath/xpath_syntax.asp .

When you go to the "Data Source" pane, what does the structure for your Main
data source look like? Without that information, I can only guess at what the
XPath expressions should be. So here goes a few guesses:

"//my:last"
"//my:dhmrn"
"//my:cdate"
 
L

Luke Slotwinski

Under my Data Source pane I have a root folder called "childrens" and in it
are
the fields of the form. The fields are defined as strings.
I tried to define the variables as :
var last = XDocument.DOM.selectSingleNode ("//my:last").text;
and as
var last = XDocument.DOM.selectSingleNode ("//childrens:last").text;
but each time i try to execute the onsaverequest I end up getting error
stating
Reference to undeclared namespace prefix: 'childrens'.
File:script.js
Line:8

Thank you for all your help S.Y.M. Wong-A-Ton, hopefully I can get this
functioning
 
S

S.Y.M. Wong-A-Ton

"childrens" is not a namespace, which is why you're getting the error.

I still do not have enough info for me to be able to help you. Add the
following line of code at the beginning of the event handler

XDocument.UI.Alert(XDocument.DOM.xml);

and post the resulting XML if it does not contain sensitive information and
isn't too large, so that I can see the exact structure of your Main data
source.
 
L

Luke Slotwinski

The following is the result of the XML:

<?xml version="1.0"?><?mso-infoPathSolution solultionVersion="1.0.0.47"
productVersion="11.0.6357"
PIVersion="1.0.0.0"
href="file:///\\DHDCHOME1\lslotwin$\sendout\childrens.xsn" name="urn:schemas-
microsoft-com:eek:ffice:infopath:childrens:-myXSD-2006-10-10T18-54-19"
?><?mso-application
progid="InfoPath.Document"?><my:childrens
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xhtml="http://www.w3.org/1999/xhtml
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-10-10T18:54:19"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:first></my:first>
<my:last></my:last>
<my:DOB></my:DOB>
<my:gender1></my:gender1>
<my:specimen_source></my:specimen_source>
<my:cdate></my:cdate>
<my:coll_time></my:coll_time>
<my:dhmrn></my:dhmrn>
<my:fac_acc>ZZDHMC</my:fac_acc>
<my:pri></my:pri>
<my:call_results></my:call_results>
<my:pEPCR>false</my:pEPCR>
<my:VEM>false</my:VEM>
<my:pHETRY>false</my:pHETRY>
</my:childrens>

Thanks,
Luke
 
S

S.Y.M. Wong-A-Ton

Try these 3 XPath expressions, Luke:

"my:childrens/my:last"
"my:childrens/my:dhmrn"
"my:childrens/my:cdate"

I find it strange, though, because the ones that I suggested in one of my
previous posts should have worked. Let me know if these ones do.

If they do not work, try finding out which do and which don't by adding
XDocument.UI.Alert(...) to your code to test whether each node is null or not.

Example:
XDocument.UI.Alert(XDocument.DOM.selectSingleNode("my:childrens") == null);

if it returns False, check

XDocument.UI.Alert(XDocument.DOM.selectSingleNode("my:childrens/my:cdate")
== null);

etc.
 
L

Luke Slotwinski

Wong-A-Ton
That did it !!! Thank you so much for your help. I do have one more
question...
Is it possible to add in code for after save request to initiate the Print
command?
It would make it easier for the end-user to only have to push one button, to
save and then it would automatically bring up a print screen.

Thanks,
Luke
 
S

S.Y.M. Wong-A-Ton

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top