Skip to main content
Participating Frequently
November 29, 2016
Answered

Open PDF Form before running Document Level scrip

  • November 29, 2016
  • 2 replies
  • 1624 views

I have this Code in a document level script. The problem I am encountering is that this question box shows up before the actual form loads. I need to ensure that the form is blank before this pops up and before any other script is run. I cant fiqure this out and can use some help

var vButton = app.alert({  
cMsg: "Do you want to advance the report number?", 
cTitle: "A message from Dan Sajdak",   nIcon: 2, nType: 3  });
if ( vButton == 4  )
{

//Increase Reprt Number
this.getField("REPORT NUMBER").value ++ ;
this.getField("REPORT NUMBER").defaultValue = this.getField("REPORT NUMBER").value ;

This topic has been closed for replies.
Correct answer gkaiseril

This did not work Joel. No errors however, a white message box showed up briefly and then the page loaded. Never got the option of increasing the report number.


Try the following code, it includes some error checking and debugging:

function IncreaseReportNumber()
{
var vButton = app.alert({
cMsg: "Do you want to advance the report number?",
cTitle: "A message from Dan Sajdak",   nIcon: 2, nType: 3  });

// some debugging code;
console.show(); console.clear();
console.println("Response: " + vButton);

if ( vButton == 4  )
{
//Increase Reprt Number
var oField = this.getField("REPORT NUMBER");

// more debugging code;
console.println("before field value: " + oField.value);
console.println("before field default value: " + oField.defaultValue);


if(oField == null) app.alert("Error in field name: REPORT NUMBER\Check spelling and capitalizaton.", 1, 0);
oField.value ++ ;
oField.defaultValue = oField.value ;

// more debugging code;
console.println("After field value: " + oField.value);
console.println("After field default value: " + oField.defaultValue);
}
else
{

// more debugging code;
app.alert("number not updated", 3, 0);

} // end response 4;
return
} // end IncreaseReportNumber function;

IncreaseReportNumber();

2 replies

Inspiring
November 29, 2016

All scripts in the document level section are executed upon opening the application. A block of code placed within a function will not execute but the function will be syntax checked and tokenized. Then one only needs to call the function once the form is known to be open. The "On page open" action will execute when a page is open, this also means that the PDF has been opened. You can add code to the first page of the PDF that calls the function and possibly contains code so it is only executed once.

Participating Frequently
November 29, 2016

Thanks MVP.............I am not familiar at all with the "On page open" command. I am trying to research with no luck so far. I am getting a big headache from this issue!!!!!!!!!!!!

Joel Geraci
Community Expert
Community Expert
November 29, 2016

Are you saying that the message pops up before the document is drawn on the screen? If so, wrap your code in a function and then add it to an app.setTimeOut() method. Give it a delay of 250 milliseconds or so. If that's not what's happening, please elaborate.

Participating Frequently
November 29, 2016

That is exactly what I am saying Joel however, when I added the code, the same thing happened. Here is the code now:

function IncreaseReportNumber()

app.setTimeOut('“function.IncreaseReportNumber”',250)

{var vButton = app.alert({  
cMsg: "Do you want to advance the report number?", 
cTitle: "A message from Dan Sajdak",   nIcon: 2, nType: 3  });
if ( vButton == 4  )
{

//Increase Reprt Number
this.getField("REPORT NUMBER").value ++ ;
this.getField("REPORT NUMBER").defaultValue = this.getField("REPORT NUMBER").value ;
app.setTimeOut('“IncreaseReportNumber”',160000)

}}

Joel Geraci
Community Expert
Community Expert
November 29, 2016

You've  got the code a bit jumbled. You need to define the function first and then call it via the time out. Try this...

function IncreaseReportNumber() {
     var vButton = app.alert({             
          cMsg: "Do you want to advance the report number?",
          cTitle: "A message from Dan Sajdak",
          nIcon: 2,          
          nType: 3
     });      
     if ( vButton == 4  ) {
           //Increase Reprt Number
           this.getField("REPORT NUMBER").value ++ ;
           this.getField("REPORT NUMBER").defaultValue = this.getField("REPORT NUMBER").value ;
      }
}
app.setTimeOut("IncreaseReportNumber",250)