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

How to Abort a Series of Button Actions

SandieB83
Registered: Nov 4 2010
Posts: 10
Answered

I have an Acrobat Form with a button that executes a series of actions. The first action is an alert with an explanation of everything the button will do. At the end of the alert, I have "Do you want to continue?" At the moment, regardless of whether "YES" or "NO" is clicked, all of the actions still execute. How do I tell it not to do the remaining actions if the user selects "NO"? (I am a very beginner javascript user. Please be gentle and very simple. Thank you.)
 
I am using Windows, Acrobat Pro 9.4.0

My Product Information:
Acrobat Pro, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Without seeing your code, it is hard to tell how you are controlling the process. You should be able to custom code an action to terminate or not execute the balance of the code. I would use a simple alert and check the response to then run a function or do nothing.

function MyProcess() {
app.alert("Hello World!", 3, 0);
return true;
}

var cResponse = app.alert({cMsg: "An alert will appear\continue?", nIcon: 2, nType: 2, cTitle: "Explanation"});
if (cResponse == 4) {
if(app.alert("Confirm continue:", 2, 3) == 4) {
MyProcess();
} else {
// do nothing
} // end continue loop
} // end response is yes



George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You cannot prevent separate subsequent actions from getting triggered. But depending on what those other actions are, you may be able to implement them all in JavaScript, in which case you can use a single JavaScript action and control which code is executed.

So, what are the subsequent actions, exactly?
SandieB83
Registered: Nov 4 2010
Posts: 10
Thank you to both Georges for rsponding so quickly. Here is the additional information.

This is an inventory tracking form. After all the data has been entered by the end of the year, I want the user to be able to use this form to begin the next year as well. So the "Start New Year Button" is supposed to prompt them to save this year's data then move all of the end of year inventory totals to the beginning of the year and clear all of the other data. Since it may not be clear to the user what the button will do, I want to start with an alert box explaining the steps and offering them an "out" if they are not ready to do that.

On the Button Action tab, I have the following steps:

Mouse Up
Run a JavaScript
Execute a menu item
File>Save As....
Run a JavaScript
Reset a form
Run a JavaScript

The code in the first JavaScript is this: (I have broken the lines apart to make it easier to read.)
// Explanation of "Start New Year" Button Function
app.beep(0);
app.alert("Pressing this button causes several things to happen: \n\n
1. You will be prompted to save the file with all of this year's information. \n\n
2. The Ending inventory counts to become the Beginning Inventory for the next year.\n\n
3. All other values will be cleared except the Description column and the Beginning Inventory column \n\n
4. The years will be incremented to begin your file for the new year. \n\n \n\n
Do you want to continue?",3,2);

The second step then prompts the user to save the data they've entered. (This form will have Features Extended into Adobe Reader.)

The code in the second JavaScript is this: (this works fine)
// get object
var v1 = +getField("OnHandEndingAug31Row1").value;
// insert into form field
this.getField("OnHandBeginningSept1Row1").value = v1;

// get object
var v1 = +getField("OnHandEndingAug31Row2").value;
// insert into form field
this.getField("OnHandBeginningSept1Row2").value = v1;

....etc. down to.....



// get object
var v1 = +getField("OnHandEndingAug31Row13").value;
// insert into form field
this.getField("OnHandBeginningSept1Row13").value = v1;

Next step is Reset a Form:
In this step I reset all of the fields, except the descriptions and beginning inventory fields.

In the final JavaScript step, I want to increment the Years that have been entered to the next year. The user initially enters values to go into a title which says "Inventory for September 20__ to August 20__". I do not quite have this working yet but I'm close.

It's the first JS that my original question referred to. When I ask the user if they want to continue or not, if they say "no", how do I not do the additional steps inside the button? Obviously if they say "yes", it continues just fine.

I apologize for the length here but I wanted to be very clear. Thank you for any insight you can give.

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The problem will be the requirement to save. You can do a Save As with JavaScript, but you have to supply a file path (location + name), and it will only work with Reader if you set up a folder-level script, which means it has to be installed on each user's machine. If this is not a problem, the rest of what you want can be implemented with JavaScript. See the doc.resetForm method in the documentation, which can be used to reset certain fields and not others.
SandieB83
Registered: Nov 4 2010
Posts: 10
George J,
Where do I find this documentation for doc.resetForm? I've looked in Acrobat Help and googled it and have not had any success. Sorry to be such a newbie.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.523.php
SandieB83
Registered: Nov 4 2010
Posts: 10
Accepted Answer
Thank you to both of you for your help. I have finally completed this JS for inside a button. It creates a function which does everything I need so that the action can be aborted if necessary in the Alert Box at the very end. Inside the function I reassign code from one field to another in each row; I reset all the fields that need to be blanked. And I cause the year fields to increment to setup for the next year.

Thanks again for your help. I learned much in the process of sorting this out.

The final code is this:

function StartNewYear() {
// Reset inventory values for beginning of year
// get object
var v1 = +getField("OnHandEndingAug31Row1").value;
// insert into form field
this.getField("OnHandBeginningSept1Row1").value = v1;

var v1 = +getField("OnHandEndingAug31Row2").value;
this.getField("OnHandBeginningSept1Row2").value = v1;

var v1 = +getField("OnHandEndingAug31Row3").value;
this.getField("OnHandBeginningSept1Row3").value = v1;

var v1 = +getField("OnHandEndingAug31Row4").value;
this.getField("OnHandBeginningSept1Row4").value = v1;

var v1 = +getField("OnHandEndingAug31Row5").value;
this.getField("OnHandBeginningSept1Row5").value = v1;

var v1 = +getField("OnHandEndingAug31Row6").value;
this.getField("OnHandBeginningSept1Row6").value = v1;

var v1 = +getField("OnHandEndingAug31Row7").value;
this.getField("OnHandBeginningSept1Row7").value = v1;

var v1 = +getField("OnHandEndingAug31Row8").value;
this.getField("OnHandBeginningSept1Row8").value = v1;

var v1 = +getField("OnHandEndingAug31Row9").value;
this.getField("OnHandBeginningSept1Row9").value = v1;

var v1 = +getField("OnHandEndingAug31Row10").value;
this.getField("OnHandBeginningSept1Row10").value = v1;

var v1 = +getField("OnHandEndingAug31Row11").value;
this.getField("OnHandBeginningSept1Row11").value = v1;

var v1 = +getField("OnHandEndingAug31Row12").value;
this.getField("OnHandBeginningSept1Row12").value = v1;

var v1 = +getField("OnHandEndingAug31Row13").value;
this.getField("OnHandBeginningSept1Row13").value = v1;

//Reset all other fields
var fields = new Array();
fields[1] = "Purchased During YearRow1";
fields[2] = "Purchased During YearRow2";
fields[3] = "Purchased During YearRow3";
fields[4] = "Purchased During YearRow4";
fields[5] = "Purchased During YearRow5";
fields[6] = "Purchased During YearRow6";
fields[7] = "Purchased During YearRow7";
fields[8] = "Purchased During YearRow8";
fields[9] = "Purchased During YearRow9";
fields[10] = "Purchased During YearRow10";
fields[11] = "Purchased During YearRow11";
fields[12] = "Purchased During YearRow12";
fields[13] = "Purchased During YearRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Produced During YearRow1";
fields[2] = "Produced During YearRow2";
fields[3] = "Produced During YearRow3";
fields[4] = "Produced During YearRow4";
fields[5] = "Produced During YearRow5";
fields[6] = "Produced During YearRow6";
fields[7] = "Produced During YearRow7";
fields[8] = "Produced During YearRow8";
fields[9] = "Produced During YearRow9";
fields[10] = "Produced During YearRow10";
fields[11] = "Produced During YearRow11";
fields[12] = "Produced During YearRow12";
fields[13] = "Produced During YearRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Other IncreaseRow1";
fields[2] = "Other IncreaseRow2";
fields[3] = "Other IncreaseRow3";
fields[4] = "Other IncreaseRow4";
fields[5] = "Other IncreaseRow5";
fields[6] = "Other IncreaseRow6";
fields[7] = "Other IncreaseRow7";
fields[8] = "Other IncreaseRow8";
fields[9] = "Other IncreaseRow9";
fields[10] = "Other IncreaseRow10";
fields[11] = "Other IncreaseRow11";
fields[12] = "Other IncreaseRow12";
fields[13] = "Other IncreaseRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Explain Other IncreaseRow1";
fields[2] = "Explain Other IncreaseRow2";
fields[3] = "Explain Other IncreaseRow3";
fields[4] = "Explain Other IncreaseRow4";
fields[5] = "Explain Other IncreaseRow5";
fields[6] = "Explain Other IncreaseRow6";
fields[7] = "Explain Other IncreaseRow7";
fields[8] = "Explain Other IncreaseRow8";
fields[9] = "Explain Other IncreaseRow9";
fields[10] = "Explain Other IncreaseRow10";
fields[11] = "Explain Other IncreaseRow11";
fields[12] = "Explain Other IncreaseRow12";
fields[13] = "Explain Other IncreaseRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "SoldRow1";
fields[2] = "SoldRow2";
fields[3] = "SoldRow3";
fields[4] = "SoldRow4";
fields[5] = "SoldRow5";
fields[6] = "SoldRow6";
fields[7] = "SoldRow7";
fields[8] = "SoldRow8";
fields[9] = "SoldRow9";
fields[10] = "SoldRow10";
fields[11] = "SoldRow11";
fields[12] = "SoldRow12";
fields[13] = "SoldRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Fed to LivestockRow1";
fields[2] = "Fed to LivestockRow2";
fields[3] = "Fed to LivestockRow3";
fields[4] = "Fed to LivestockRow4";
fields[5] = "Fed to LivestockRow5";
fields[6] = "Fed to LivestockRow6";
fields[7] = "Fed to LivestockRow7";
fields[8] = "Fed to LivestockRow8";
fields[9] = "Fed to LivestockRow9";
fields[10] = "Fed to LivestockRow10";
fields[11] = "Fed to LivestockRow11";
fields[12] = "Fed to LivestockRow12";
fields[13] = "Fed to LivestockRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "SeededRow1";
fields[2] = "SeededRow2";
fields[3] = "SeededRow3";
fields[4] = "SeededRow4";
fields[5] = "SeededRow5";
fields[6] = "SeededRow6";
fields[7] = "SeededRow7";
fields[8] = "SeededRow8";
fields[9] = "SeededRow9";
fields[10] = "SeededRow10";
fields[11] = "SeededRow11";
fields[12] = "SeededRow12";
fields[13] = "SeededRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Loss from Cleaning or ShrinkageRow1";
fields[2] = "Loss from Cleaning or ShrinkageRow2";
fields[3] = "Loss from Cleaning or ShrinkageRow3";
fields[4] = "Loss from Cleaning or ShrinkageRow4";
fields[5] = "Loss from Cleaning or ShrinkageRow5";
fields[6] = "Loss from Cleaning or ShrinkageRow6";
fields[7] = "Loss from Cleaning or ShrinkageRow7";
fields[8] = "Loss from Cleaning or ShrinkageRow8";
fields[9] = "Loss from Cleaning or ShrinkageRow9";
fields[10] = "Loss from Cleaning or ShrinkageRow10";
fields[11] = "Loss from Cleaning or ShrinkageRow11";
fields[12] = "Loss from Cleaning or ShrinkageRow12";
fields[13] = "Loss from Cleaning or ShrinkageRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Other DecreaseRow1";
fields[2] = "Other DecreaseRow2";
fields[3] = "Other DecreaseRow3";
fields[4] = "Other DecreaseRow4";
fields[5] = "Other DecreaseRow5";
fields[6] = "Other DecreaseRow6";
fields[7] = "Other DecreaseRow7";
fields[8] = "Other DecreaseRow8";
fields[9] = "Other DecreaseRow9";
fields[10] = "Other DecreaseRow10";
fields[11] = "Other DecreaseRow11";
fields[12] = "Other DecreaseRow12";
fields[13] = "Other DecreaseRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "Explain Other DecreaseRow1";
fields[2] = "Explain Other DecreaseRow2";
fields[3] = "Explain Other DecreaseRow3";
fields[4] = "Explain Other DecreaseRow4";
fields[5] = "Explain Other DecreaseRow5";
fields[6] = "Explain Other DecreaseRow6";
fields[7] = "Explain Other DecreaseRow7";
fields[8] = "Explain Other DecreaseRow8";
fields[9] = "Explain Other DecreaseRow9";
fields[10] = "Explain Other DecreaseRow10";
fields[11] = "Explain Other DecreaseRow11";
fields[12] = "Explain Other DecreaseRow12";
fields[13] = "Explain Other DecreaseRow13";
this.resetForm(fields);

var fields = new Array();
fields[1] = "OnHandEndingAug31Row1";
fields[2] = "OnHandEndingAug31Row2";
fields[3] = "OnHandEndingAug31Row3";
fields[4] = "OnHandEndingAug31Row4";
fields[5] = "OnHandEndingAug31Row5";
fields[6] = "OnHandEndingAug31Row6";
fields[7] = "OnHandEndingAug31Row7";
fields[8] = "OnHandEndingAug31Row8";
fields[9] = "OnHandEndingAug31Row9";
fields[10] = "OnHandEndingAug31Row10";
fields[11] = "OnHandEndingAug31Row11";
fields[12] = "OnHandEndingAug31Row12";
fields[13] = "OnHandEndingAug31Row13";
this.resetForm(fields);

//var fields = this.getfield("NegTotDed");
//this.resetForm(fields);

//var fields = this.getfield("TotDed");
//this.resetForm(fields);

// Increment Year values
var v1 = +getField("Year2").value;
this.getField("Year1").value = v1;

//Remind to save new version
app.beep(0);
app.alert("Don't forget to save this new document under a new name!", 3)

return true;
}

// Explanation of "Start New Year" Button Function
app.beep(0);
var cResponse=app.alert({cMsg:"Are you ready to start a new document for the next year? \n\n IF YOU HAVE NOT SAVED YOUR DOCUMENT with this year's complete data, \n press NO and go save your file. \n\n If you have saved your data and are ready to begin a new document for the \n coming year, press YES. \n\n Pressing YES will cause the following to happen. \n\n A. The Ending inventory counts will become the Beginning Inventory for the next year.\n\n B. All values will be cleared except the Description column and the Beginning Inventory column \n\n C. The years will be incremented to begin your file for the new year. \n\n \n\n Do you want to continue?", nIcon:1, nType:2,cTitle:"Are you ready to start a new document for the next year?"})

if (cResponse == 4) {
if(app.alert("Confirm continue:", 2, 3) == 4) {
StartNewYear();
} else {
// do nothing
} // end continue loop
} // end response is yes