These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

A javascript for an email submission button which was perfect in Acrobat 9 will not play nice in Acrobat X.

kymgardiner
Registered: Nov 24 2010
Posts: 6

Hello All
 
As per the subject, what was working in 9 is behaving very differently in X.
 
Now I understand there have been changes but I cannot decipher how they impact on this script. In X, the button will still work but it launches and sends the email with the PDF attached in one invisible action, whereas it previously opened an email where extra information/attachments could be added. This is particularly important for this forms functionality.
 
If I open the below script in X (Properties > Actions > Run a JavaScript) it receives errors that disallow it from being saved. It was never an issue in 9. A colleague who is very familiar with scripting cannot diagnose the issue either and his debugging options thinks it fine too. I absolutely hope that someone here has that snippet of information which makes sense of all this new found chaos....
 
Thanks for looking.
 
// These are the required fields on the form.
// Populate array with their names.
var RequiredFields = new Array(25);
RequiredFields[0] = '*****';
RequiredFields[1] = '*****';
RequiredFields[2] = '*****';
RequiredFields[3] = '*****';
RequiredFields[4] = '*****';
RequiredFields[5] = '*****';
RequiredFields[6] = '*****';
RequiredFields[7] = '*****';
RequiredFields[8] = '*****';
RequiredFields[9] = '*****';
RequiredFields[10] = '*****';
RequiredFields[11] = '*****';
RequiredFields[12] = '*****';
RequiredFields[13] = '*****';
RequiredFields[14] = '*****';
RequiredFields[15] = '*****';
RequiredFields[16] = '*****';
RequiredFields[17] = '*****';
RequiredFields[18] = '*****';
RequiredFields[19] = '*****';
RequiredFields[20] = '*****';
RequiredFields[21] = '*****';
RequiredFields[22] = '*****';
RequiredFields[23] = '*****';
RequiredFields[24] = '*****';

// These are the alert messages shown when a required field is empty.
// Populate array with messages.
// Make sure there's one message for each required field.

var alertMsg = ' is a required field - Please enter your information';

var bSuccess=true
var emptyTest = /^[\s -]*$/;
var fieldCount = RequiredFields.length
var fld = 0;

for (var i=0; i < fieldCount; i++) {
fld = this.getField(RequiredFields[i]);
if(emptyTest.test(fld.value) ) // if required field is empty
{
bSuccess=false;
app.alert(RequiredFields[i] + alertMsg);
fld.setFocus();
break;
}
}
if(bSuccess) {

var address = ' ';
if (this.getField('OMS').value == '**') {
address = '***@***.***.**';

} else {
address = '***@***.***.**';
}
 
var subj = this.getField('*****').value + ' - ' + this.getField('*****').value + '*****' + this.getField('*****').value + '*****' + this.getField('*****').value;
var msgBody = 'Blah blah\n\nBlah blah blah.\n\nBlah.';

////message box with instructions to add email addresses
var cResponse = app.alert({
cMsg: 'Blah.\n\nBlah.\n\nBlah email.\nClick NO to go back and continue editing the blah.',
nIcon: 2,
nType: 2,
cTitle: 'Emailing Job Docket'});

// proceed only if response is 'YES'
if (cResponse == 4) {
this.mailDoc({
bUI: false,
cTo: address,
cSubject: subj,
cMsg: msgBody,
cSubmitAs: 'PDF'
});
}
}

My Product Information:
Acrobat Pro 10.1, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
What happens if you set bUI to true? It is supposed to default to that if the code is in a button event, so it would be interesting of it makes a difference.

You say you're getting errors that "disallow it from being saved." Can you clarify what you mean and post the exact text of the errors you're seeing?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I think you need to use the privileged method and for version X installations place the application folder level script in the new privileged folder recently added by an update to Acrobat X.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
mailDoc does not require a privileged context to run.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
But does appy for a JavaScript save action and the PDF needs to be saved before being emailed.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
That's true. Many people have reported this as an issue in Acrobat X that files must be saved before they can be emailed. It could also be the issue here.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

kymgardiner
Registered: Nov 24 2010
Posts: 6
George_Johnson wrote:
What happens if you set bUI to true? It is supposed to default to that if the code is in a button event, so it would be interesting of it makes a difference.You say you're getting errors that "disallow it from being saved." Can you clarify what you mean and post the exact text of the errors you're seeing?
Thank you all for your responses.

When I set to true I still receive the same error - which is:
SyntaxError: unterminated string literal
54: at line 55
It highlights the line 'address = "****@****.***.**"; the one before } else {

What I mean by it not allowing me to save is that because of this error it will not let me select 'OK' to close the JavaScript editor. Only if I 'Cancel' will it close.

I apologise for pleading ignorance here but I am not familiar with privileged method. As I was adding this script in the Properties section of the button I assumed it was all contained within the file, not in folders elsewhere.

It would seem the PDF is still being saved by the form user as it attaches the form to the email but the problem is it is not keeping the email open. It just sends the email in one invisible action when you hit submit. So if a end user is using Ac9 Reader, when they hit submit it will open an email with the file attached and fields populated. If they are using AcX Reader they hit submit and all they can see is the email submitting in their outbox (with attachments and fields correctly populated). There is no interim step of viewing and sending the email for them.

I should mention that this PDF has Extended Features / Enable Usage Rights turned on for the users of the form.

Any advice is greatly appreciated.

Thanks.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Make sure you're using the same type of quotes on both ends of the string. Also, if the string contains a back-slash or a quotes symbol, it must be escaped by placing a back-slash before it.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

kymgardiner
Registered: Nov 24 2010
Posts: 6
try67 wrote:
That's true. Many people have reported this as an issue in Acrobat X that files must be saved before they can be emailed. It could also be the issue here.
So is there an alternative script I could use to resolve the saving issue?

The form is used by our sales teams to submit jobs for production, all I have ever provided them with was the enabled PDF. I have never had to set folders or background files up for the end users or myself. Because my file is self contained does this mean that the privileged folder issue is not relevant?

My colleagues here who are java readers say that there in nothing wrong with the script, but they aren't Acrobat users so there is a disconnect in our ability to resolve the issue.

If anyone could offer any advice to repair or workaround this submission issue I would be incredibly thankful as I have hit the wall with my current expertise.

Thank you.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Are you still getting this error message ("SyntaxError: unterminated string literal")? If so, then the problem is in the script itself. Post the code and someone might spot it.
The message you're quoting was regarding something else. In Acrobat X it's no longer possible to email a file that hasn't been saved yet. This is not scripting-related. It's just how this application behaves.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com