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

Three button alert

Grika
Registered: Dec 9 2009
Posts: 35
Answered

I have an alert window that requests information before extracting certain fields from a form and putting their data into an email. I want the Cancel button to simply close the alert without generating the email.

The alert code looks like this:
var oDlg = app.alert({
cMsg: "Is the device OK to place?",
cTitle: "Placement Verification",
nIcon: 2, nType: 3
});
if ( oDlg == 4 ) var cOkay="OK";
if ( oDlg == 3 ) var cOkay="NOT OK";

I would hope that there would be an easy way to set oDlg == 2 to do nothing. As it is, the Cancel button sets cOkay to "OK" and produces the email.

My suspicion is that I need to wrap my entire code in a function or something so that I can escape the window. I've tried such a scheme adding a "break;" but I always get an "invalid break" error no matter what I do.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
How are you sending the email?

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

Grika
Registered: Dec 9 2009
Posts: 35
With:

app.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});

cBody contains the alert response, selected field values and some additional text.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
They why not simply place this line after you check what the response was? Something like:
if ( oDlg == 4 ) { // The user clicked Yesapp.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});}

There's no need to check for any other options.

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

Grika
Registered: Dec 9 2009
Posts: 35
Except that I need cBody to contain either "OK" or "NOT OK" depending on if the Yes or NO buttons were selected respectively.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
So you want to send the email if either Yes or No were selected, but not if Cancel was selected? Then do this:
if ( oDlg == 4 ) { // The user clicked Yesvar cOkay="OK";// do some other stuffapp.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});}else if ( oDlg == 3 ) { // The user clicked Novar cOkay="NOT OK";// do some other stuffapp.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});}

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

Grika
Registered: Dec 9 2009
Posts: 35
Just so I'm sure I'm not missing some cleaner notation, your method would really be:

if ( oDlg == 4 ) { // The user clicked Yes
var cOkay="OK";
// [b]notate some stuff[/b]
app.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});
}
else if ( oDlg == 3 ) { // The user clicked No
var cOkay="NOT OK";
// [b]notate ALL the same stuff again[/b]
app.mailMsg({bUI: true, cTo: "", cSubject: cSubLine, cMsg: cBody});
}


Sure I can copy and paste the entire script but is there some way to create a loop or something for clarity's sake?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I'm not sure what you mean by "notate some stuff", but if you have a lot of code that is identical, just place it in a function, so you don't need to copy-paste it.

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

Grika
Registered: Dec 9 2009
Posts: 35
Looks like we have success!

I placed all the field related variables at the beginning of the script, created a function of the code that pulls together the information and builds the email and called that function from within the"if" statements of the alert.

Thank you for all your help.