Skip to main content
Known Participant
April 4, 2024
Question

Optimising Database Display

  • April 4, 2024
  • 1 reply
  • 453 views

Hello,

I have a very specific problem that i am trying to tackle. I am trying to make something of a manual for spare parts for several machines at work and i want to make it into a pdf form. I have made the sheet and using javascript organised all the textboxes the way i need to but when i try to populate each box the document lags like crazy. I need some guidance on how to optimise it. let me elaborate. I have a combo box with all the machines "machine_1, machine_2... _7" i also have another combobox listing the sub-parts of the saind machine "machine_1_1, machine_1_2... _1_10"  i also have a list of fiedls that need to be populated. I have set it in such a way that every time i chose a machine from the first combo box a script it activated to reset all of the used fields "function ResetMachines()
{
this.resetForm ([
"Machine.1.Level",
"Machine.1.Title",
"Machine.1.Description",
"Machine.1.Title_02",
"Machine.1.Description_02",
"Machine.1.Title_03",
"Machine.1.Description_03",
"Machine.1.Title_04",
.....
"Machine.6.Level",
"Machine.6.Title",
"Machine.6.Description",
"Machine.6.Title_02",
"Machine.6.Description_02",
"Machine.6.Title_03",
"Machine.6.Description_03",
"Machine.6.Title_04",
"Machine.6.Description_04"]);
}"

afterwads the second combobox calls out a script to populate them.

function partsMachines(Machines) {
var partsMachines = Circle[Machines];

// Loop through each field and populate if empty
for (var i = 1; i <= 6; i++) {
var fieldPrefix = "Machines." + i + ".";
var levelField = this.getField(fieldPrefix + "Level");
var titleField = this.getField(fieldPrefix + "Title");
var descriptionField = this.getField(fieldPrefix + "Description");
var title02Field = this.getField(fieldPrefix + "Title_02");
var description02Field = this.getField(fieldPrefix + "Description_02");
var title03Field = this.getField(fieldPrefix + "Title_03");
var description03Field = this.getField(fieldPrefix + "Description_03");
var title04Field = this.getField(fieldPrefix + "Title_04");
var description04Field = this.getField(fieldPrefix + "Description_04");

levelField.value = partsMachines["Machines_" + i + "_Level"];
titleField.value = partsMachines["Machines_" + i + "_Title"];
descriptionField.value = partsMachines["Machines_" + i + "_Description"];
title02Field.value = partsMachines["Machines_" + i + "_Title_02"];
description02Field.value = partsMachines["Machines_" + i + "_Description_02"];
title03Field.value = partsMachines["Machines_" + i + "_Title_03"];
description03Field.value = partsMachines["Machines_" + i + "_Description_03"];
title04Field.value = partsMachines["Machines_" + i + "_Title_04"];
description04Field.value = partsMachines["Machines_" + i + "_Description_04"];

}

 

It all works as intended but it is so slow and laggy that i don't think it is usable. I know i am pushing the limit of the whole pdf javascript capabilities but i am also sure there is a better way to optimise this. Any ideas?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 4, 2024

Where did you place the code?

Known Participant
April 4, 2024

I have made two separate Document Java scrips, which i am calling from a field, depending on its level.

However, i beleive i have solved or at least deligated my problem. I am using the field to call the function bit by bit depending on the fields i need populated. This is in the calculation section of the calling field, and it works like a charm:

 

var fieldValue = parseInt(event.value);

var i;

if (fieldValue >= 6 && fieldValue < 10) {
i = 2;
} else if (fieldValue >= 10 && fieldValue < 14) {
i = 3;
} else if (fieldValue >= 14 && fieldValue < 18) {
i = 4;
} else if (fieldValue >= 18) {
i = 5;
} else {
// Default case or handle any other conditions
i = 1; // or any other appropriate default value
}

// Call CircleAbilities function with calculated 'i'
CircleAbilities(this.getField("Random Machine Name").value, i);

and also removing the for (var i=...) loop in my function and replacing it with:
function partsMachines(Machines, i)

 

it is still the same code and same "weight" but it is doing it bit by bit and i will never need to execute it all from 1 till 7, so that is a good solution so far. However, if someone has a better one, i am oppened to it

try67
Community Expert
Community Expert
April 4, 2024

What I meant was, from which event of the field are you calling the function? Calculate? Validate? Mouse Up? Something else?