Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Open the document if other rules don't apply

Participant ,
Nov 21, 2017 Nov 21, 2017

I have an alert in document-level that opens if a certain button is not hidden and then when that button is hidden, the alert doesn't open.  So that works fine but when I tried adding a second alert, I get issues.  What I'm trying to accomplish is there are two parts to a pdf form (PART I and PART II).  If part 1 doesn't have a button hidden, then an alert will pop up when the document is opened.  After part 1 has been digitally signed, the button will hide and that alert won't popup anymore but a second alert will pop up if part 1's button hidden AND part 2's button is not hidden.  Once part 2 has been signed, part 2's button is hidden and no more alerts should pop up.

It all works up to the last part.  The second alert still pops up even though both buttons are hidden.  Here's my code:

var VerifyPartI = this.getField("Verify PART I");

var VerifyPartII = this.getField("Verify PART II");

if (VerifyPartI.hidden == false){

if(app.alert("Inputted text",2,1,"Title of window")!=1) this.closeDoc(true);

} else {

if (VerifyPartII.hidden == false && VerifyPartI.hidden == true);{

app.alert("Inputted text",3,0,"Title of window");

}

}

I don't know how to close this if/then statement.

TOPICS
Acrobat SDK and JavaScript , Windows
582
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2017 Nov 21, 2017

The issue is with how the second "if" is constructed.

Get rid of the semi-colon, its ending the if before the block containing the alert.

However, in general you have some badly formed code. The second "if" should be an "else if", and include better formatting

  1. var VerifyPartI = this.getField("Verify PART I"); 
  2. var VerifyPartII = this.getField("Verify PART II"); 
  3. if (VerifyPartI.hidden == false){ 
  4.     if(app.alert("Inputted text",2,1,"Title of window")!=1) this.closeDoc(true); 
  5. } else if (!VerifyPartII.hidden && VerifyPartI.hidden){ 
  6.     app.alert("Inputted text",3,0,"Title of window"); 

There is no reason to compare something to true or false, since these values are already true or false.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2017 Nov 21, 2017

Thom,

I'm using that second if to state that if they click the cancel button, the document closes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2017 Nov 21, 2017
LATEST

Thom and George,

The removal of that semicolon fixed the issue along with the change of George's suggestion.  Thanks ya'll!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2017 Nov 21, 2017

It seems like this is what you're after:

if (VerifyPartI.hidden == false) {

    if (app.alert("Inputted text", 2, 1, "Title of window")  != 1) {

        this.closeDoc(true);

    }

   

} else { 

    if (VerifyPartII.hidden == false) { 

        app.alert("Inputted text", 3, 0, "Title of window"); 

    } 

}

Though it could be simplified a bit. Note that the "hidden" field property has been deprecated in favor of the "display" field property, which can have four possible values.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2017 Nov 21, 2017

George,

I tried that and it does the same thing as the original script.  After both buttons are hidden, the second alert still comes up when the doc is open.  Once both buttons are hidden, the form doesn't need anymore alerts to popup.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines