Highlighted

Javascrip execution is slooooooow

New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

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";}

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

93

Likes

Translate

Translate

Report

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

Javascrip execution is slooooooow

New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

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";}

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

94

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 02, 2020 0
Contributor ,
Sep 02, 2020

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 1
Adobe Community Professional ,
Sep 02, 2020

Copy link to clipboard

Copied

Sorry Asim123, 

 

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
Contributor ,
Sep 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

not worries. What happens is when running the code from the calculate tab the code executes after each scan so it's always erasing the field values and then reinstalling the this.getField().values of the selection. I executes extremely fast, but if I try and put manually enter a time into one of those fields the code erases it and reinstalls whater is in attached to the drop box selection.

 

When this code is installed into the validate tab of the drop box property the code only runs once after the event.value changes which allows my to input manual times in these fields without them being erased. aThe down side it the code executes extremely slow in the validate tab. Thank you for responding. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

No worries, manually imputting times in the hh:mm format. outside of the nornal hours, like overtime. ...."18:30" and such.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
Adobe Community Professional ,
Sep 02, 2020

Copy link to clipboard

Copied

++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...

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
Adobe Community Professional ,
Sep 02, 2020

Copy link to clipboard

Copied

 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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

Yes, if I delete all of the txet and conntent, just leaving the form fields and code it should be fine. How do I attach it?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
Most Valuable Participant ,
Sep 02, 2020

Copy link to clipboard

Copied

I'm sorry, but this is bad advice. Think about what happens when you run this code, step by step... Basically, only the last if-else section matters at all. Everything before it will be overwritten no matter what the value is, because the value of the event is either 4, or it's not 4. That covers all possible values, so everything before it is moot.

 

The original code is fine, and should not take more than a few milliseconds to execute. If it doesn't it means there's something else at play here, like other calculation scripts that are also executing at the same time, or some badly built calculation formula (circular logic) or something like that. One way of trying to avoid the former is to disable automatic calculations at the top of the code and then enable it at the end, because each time you change the value of any field, you're triggering all the calculation events of all fields.

To do it use this code:

 

this.calculate = false;

// rest of code goes here

this.calculate = true;

this.calculateNow();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 2
New Here ,
Sep 02, 2020

Copy link to clipboard

Copied

That is definitley muct faster. Still not instant, but I have a new direction to play with it. THANK YOU!!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Sep 02, 2020

Copy link to clipboard

Copied

Thank you for clarifying try67.

 

Always saving the day.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 02, 2020 0