Javascript issue with submitForm
Copy link to clipboard
Copied
My form has a button with a javascript associated to the Mouse Up event.
The script code follows:
if (FormOk()==true) {
//Confirmation request
var nButton = app.alert({
cMsg: "Do you want to submit this application form?",
cTitle: "Submit form", nIcon: 2, nType: 2});
if ( nButton == 4 ) {
//Form collection email address
cToAddr = "mailbox@example.com";
// Set the subject and body text for the email message
var cSubLine = "Application for Employment";
// Set the subject and body text for the email message
var cBody = "Instructions to handle this application form:\n" +
"1. Double-click the attachment\n" +
"2. Select a response file";
//Build email URI
var cURI = encodeURI("mailto:" + cToAddr + "?" +
"subject="+ cSubLine + "&body=" + cBody);
//Exception handling
try {
//Submit form by email
this.submitForm({cURL: cURI, cSubmitAs: "PDF"});
app.alert({
cMsg: "Your application has been submitted",
cTitle: "Submit form", nIcon: 3});
} catch(e) {
//Display error info
app.alert({
cMsg: "Application NOT submitted\n\n" +
e.name + " on line: " + e.lineNumber +
"\n\n" + cURI});
}
} else {
app.alert({
cMsg: "Your application WAS NOT submitted",
cTitle: "Submit form", nIcon: 3});
}
}
This should work as per the documentation but it is not and it is driving me crazy.
The issue happens using my Outlook mail client and also using Gmail webmail client.
I would appreciate any ideas about how to solve this issue.
Thanks in advance!
Copy link to clipboard
Copied
What issue? What happens when you click it? Is there an error message of some kind?
Also, did you define a function called FormOk that return a boolean?
Copy link to clipboard
Copied
Sorry I should have explained that the FormOk function performs several data validation and returns false if there is any error, true otherwise.
What happens depends on several situations:
If using Outlook mail client it silently fails and the "Your application has been submitted" alert is displayed.
If using Gmail webmail client then:
- The following dialog displays:
Clicking the Details button displays: - Clicking Yes displays several progress messages:
Preparing to Send Message ...
Connecting ...Creating Draft ...
and the following dialog: - Clicking Yes raises an exception:
Exception in line 26 of function top_level, script Field:Mouse Up
RaiseError: Error while creating message.
Doc.submitForm:26:Field Submit:Mouse Up
===> Error while creating message.
So I added the try{}..catch{} to handle the exception and got the following dialog:
which shows that the mailto URI is Ok
Now it is fully documented.

