Skip to main content
Known Participant
September 2, 2020
Question

Javascrip execution is slooooooow

  • September 2, 2020
  • 2 replies
  • 1150 views

I am using a drop box in a acrobat XI form and using the below code to populate timesheet fields depending on how many work orders have been done during the shift. If i execute the javascript in the calculate tab of the field it executes extremely fast, but won't let me input the field manually because it erases them on the next scan. If I put the code in the validate tab it executes extremely slow, like 4 seconds, but allows for manual time entries in the fields. I'v tried simplifying the code, function calls, and running as a text box, but it all comes out the same...am I stuck with the lag or does someone know a trick? Please and Thank You.

 

//Reset the FROM and TO fields

Reset2()// Resets the below fields

//Check selection and input time values

// 1 Work Order
if (event.value == 1){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "16:15";
}

// 2 Work Orders
else if (event.value == 2){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "11:45";
this.getField("FROM22").value = "12:15";
this.getField("TO22").value = "16:15";
}

// 3 Work Orders

else if (event.value == 3){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "16:15";
}

// 4 Work Orders

else if (event.value == 4){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "14:15";
this.getField("FROM24").value = "14:15";
this.getField("TO24").value = "16:15";
}

// 5 Work Orders
else if (event.value == 5){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "14:15";
this.getField("FROM24").value = "14:15";
this.getField("TO24").value = "15:15";
this.getField("FROM25").value = "15:15";
this.getField("TO25").value = "16:15";
}

// 6 Work Orders
else if (event.value == 6){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "13:15";
this.getField("FROM24").value = "13:15";
this.getField("TO24").value = "14:15";
this.getField("FROM25").value = "14:15";
this.getField("TO25").value = "15:15";
this.getField("FROM26").value = "15:15";
this.getField("TO26").value = "16:15";
}

//  Work Orders

else if (event.value == 7){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "10:45";
this.getField("FROM23").value = "10:45";
this.getField("TO23").value = "11:45";
this.getField("FROM24").value = "12:15";
this.getField("TO24").value = "13:15";
this.getField("FROM25").value = "13:15";
this.getField("TO25").value = "14:15";
this.getField("FROM26").value = "14:15";
this.getField("TO26").value = "15:15";
this.getField("FROM27").value = "15:15";
this.getField("TO27").value = "16:15";
}

// 8 Work Orders

else if (event.value == 8){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "08:45";
this.getField("FROM22").value = "08:45";
this.getField("TO22").value = "09:45";
this.getField("FROM23").value = "09:45";
this.getField("TO23").value = "10:45";
this.getField("FROM24").value = "10:45";
this.getField("TO24").value = "11:45";
this.getField("FROM25").value = "12:15";
this.getField("TO25").value = "13:15";
this.getField("FROM26").value = "13:15";
this.getField("TO26").value = "14:15";
this.getField("FROM27").value = "14:15";
this.getField("TO27").value = "15:15";
this.getField("FROM28").value = "15:15";
this.getField("TO28").value = "16:15";}

 

This topic has been closed for replies.

2 replies

ls_rbls
Community Expert
September 2, 2020

++EDITED REPLY,  made some corrections to my explanation

 

 

 

I would conclude the scripts with an IF statements with an ELSE statement. 

 

In other words use IF or ELSE statements if you must need to employ ELSE IF with something else (specially on a long testing script like this one.

 

That said, the lag may be related to all the fields that the script is reading and writing to on each iteration.

 

It makes sense to me  to close the IF statement with a condition to check make the itereations stops when the condition is not true.

 

The way you have the code setup is only testing for a condition only if it is true, yet,  there is nothing testing if that same condition is false. 

 

On the other hand ELSE IF executes to test for a new (and specific) condition and checks if the prior condition is false.

 

When you use  ELSE IF  to test for a condition that you already specified to be true, it becomes somewhat of a scripting paradox because ELSE IF expects to test for a condition that is false and keeps repeating that check until it finds if something is false.

 

You're basically telling the script to try a and test for a new condition without even checking for for a false condition because it doesn't exist; you have to create it.

 

In the example below I got rid of the ELSE IF to illustrate what I am trying to theorize here.

 

See if this helps:

 

 

if (event.value == 1) {
this.getField("FROM21").value= "07:45"; 
this.getField("TO21").value = "16:15";
} else {
this.getField("FROM21").value = ""; 
this.getField("TO21").value = "";
}


// 2 Work Orders
if (event.value == 2){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "11:45";
this.getField("FROM22").value = "12:15";
this.getField("TO22").value = "16:15";
} else {
this.getField("FROM21").value = ""; 
this.getField("TO21").value = "";
this.getField("FROM22").value = "";
this.getField("TO22").value = "";
}

// 3 Work Orders
 if (event.value == 3){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "16:15";
} else {
this.getField("FROM21").value = ""; 
this.getField("TO21").value = "";
this.getField("FROM22").value = ""; 
this.getField("TO22").value = "";
this.getField("FROM23").value = ""; 
this.getField("TO23").value = "";
}

// 4 Work Orders

if (event.value == 4){
this.getField("FROM21").value = "07:45";
this.getField("TO21").value = "09:45";
this.getField("FROM22").value = "09:45";
this.getField("TO22").value = "11:45";
this.getField("FROM23").value = "12:15";
this.getField("TO23").value = "14:15";
this.getField("FROM24").value = "14:15";
this.getField("TO24").value = "16:15";
}else {
this.getField("FROM21").value = "";
this.getField("TO21").value = "";
this.getField("FROM22").value = "";
this.getField("TO22").value = "";
this.getField("FROM23").value = "";
this.getField("TO23").value = "";
this.getField("FROM24").value = "";
this.getField("TO24").value = "";
}



//  AND SO ON...

 

Ross5E6FAuthor
Known Participant
September 2, 2020

I definitely she what you mean , and I was super excited to try that variation, but after running the code it was just as slow...really was optimistic too.

ls_rbls
Community Expert
September 2, 2020

 I forgot to ask if the results of the output in those fields ( the TO and FROM hour fields) are also  used with other calulated fields throughout the form?

 

Are you able to share a dummy file?

Inspiring
September 2, 2020

When you say you input value manualy, in what situations are you inputing them?

 

ls_rbls
Community Expert
September 2, 2020

Sorry Asim123, 

 

Seems like I 'm always crashing the topic without noticing that you were already helping. 

Inspiring
September 2, 2020

No problem 🙂  btw  english is not my first language so sometimes I have trouble understanding what OP want's , thats why I ask  a lot of questions  sometimes to be sure, for example in this post I don't get when is OP using manual input and where, because if he use event value 4 (for example) he can manually input in those 4 fields whitout reseting values but if he enter in other fields value will reset, and does he needs to save doc with those values or just print...etc so I don't want to advice him something before knowing all the facts