Expand my Community achievements bar.

SOLVED

Dynamic Form is painfully slow to open and edit

Avatar

Level 4

I'm hoping someone could take a few minutes and see if they could help me figure out why this form is so slow to 1) open, 2) add a new line, and 3) select a client in the dropdown box in the "CLIENT" column. I've tried removing the page numbering in the layout:ready event and it doesn't help the performance at all. I do have a lot of calculations and a lot of resolveNodes, but I don't think I have any other way of performing these calculations without them. If anyone could point me in the right direction.

The form is here:

https://acrobat.com/#d=pBkuyHMzab36bS4N0U9VEg

...and if you open it in Acrobat or Reader first, you'll see what I mean. It's not as slow in a preview in Livecycle because all of the entered data is gone.

Thank you for any help.

Jo

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I would like to try removing the two resolveNodes calls and the two item methods from Jono's example and see if that helped, so;

var result = 0;

var rows = this.resolveNodes("ItemSet[*]");

for (var i=0, limit=rows.length; i<limit; i++)

{

    var row = rows.item(i);

    if (row.client.rawValue === clientName.rawValue)

    {

        result += row.corresp.rawValue

    }

}

result;

But I have not timed this and am still surprised about being wrong with optimisations.

I think the big win is to remove the code from the calculate events of the the fields correspTotal, hcfaTotal, holdsMiscTotal, Total182, Total215, Total247, Total259 and Total268 (I renamed Total268 as it was a duplicate and complicated my script) and add the following code to the calculate event of clientTotals (the parent subform), so you only loop though your form once per client.

var correspTotalWork = 0;

var hcfaTotalWork = 0;

var holdsMiscTotalWork = 0;

var total182Work = 0;

var total215Work = 0;

var total247Work = 0;

var total259Work = 0;

var total268Work = 0;

var reps = P1.resolveNodes("rep[*]");

var repCount = reps.length;

for (var j=0; j<repCount; j++)

{

    var rep = reps.item(j);

    var itemSets = rep.resolveNodes("ItemSet[*]");

    var itemSetCount = itemSets.length;

    for (var i=0; i<itemSetCount; i++

    {

        var itemSet = itemSets.item(i);

        if (itemSet.client.rawValue === clientName.rawValue)

        {

            if (itemSet.corresp.rawValue > 0)

            {

                console.println(itemSet.client.rawValue+" "+itemSet.corresp.rawValue);

            }

            correspTotalWork += itemSet.corresp.rawValue;

            hcfaTotalWork += itemSet.hcfa.rawValue;

            holdsMiscTotalWork += itemSet.holdsMisc.rawValue;

            total182Work += itemSet.tic182.rawValue;

            total215Work += itemSet.tic215.rawValue;

            total247Work += itemSet.tic247.rawValue;

            total259Work += itemSet.tic259.rawValue;

            total268Work += itemSet.tic268.rawValue;

        }

    }

}

correspTotal.rawValue = correspTotalWork;

hcfaTotal.rawValue = hcfaTotalWork;

holdsMiscTotal.rawValue = holdsMiscTotalWork;

Total182.rawValue = total182Work;

Total215.rawValue = total215Work;

Total247.rawValue = total247Work;

Total259.rawValue = total259Work;

Total268.rawValue = total268Work;

The next step you could try would be to loop though the form once and maintain the eight totals per client.

To see the console messages in my previous example press Ctrl-J.  You should see some lines like;

form1.P1.rep.repTotals.Total268.#calculate:Time elapsed 3ms

form1.P1.rep.repTotals.unresolvedTotal.#calculate:Time elapsed 3ms

form1.clientTotals.correspTotal.#calculate:Time elapsed 340ms

form1.clientTotals.hcfaTotal.#calculate:Time elapsed 358ms

Good luck

Bruce

View solution in original post

26 Replies

Avatar

Level 10

Hi Jo,

You were referring to the field Result182 with a lowercase r.

Fixed that and it seems ok now, https://sites.google.com/site/livecycledesignercookbooks/home/Log_Sheet-modified.2.pdf?attredirects=...

Make sure you have "Show console on errors and messages" selected in Acrobat ... Edit ... Preferences ... JavaScript, otherwise these sort of errors go unreported and anything after that wont be executed.

Regards

Bruce

Avatar

Level 4

Thank you! My console got turned off at some point and I never could figure out how to turn it back on! I figured it would be a simple error like that!

I've updated that, and it's working better. But the problem I'm having now is that the repTotals aren't zeroing out if you change the selected client. For example, if you select any team at the top. Then select a client in the rep section, and put a number in one of the columns. That works...but if you go back and change the client to a different one, it doesn't change the first client selected back to -0-. Do you get this same behavior?

Thanks,


Jo

Avatar

Level 10

Hi,

Hadn't thought of that, try changing the following;


if (correspResult.hasOwnProperty(totalRow.clientName.rawValue))


 


totalRow.correspTotal.rawValue = correspResult[totalRow.clientName.rawValue]



To


totalRow.correspTotal.rawValue = (correspResult.hasOwnProperty(totalRow.clientName.rawValue)) ? correspResult[totalRow.clientName.rawValue] : 0;


That is set the repTotal to zero if there is nothing for the client.

Regards

Bruce

Avatar

Level 4

Thanks Bruce! That actually fixes the issue and makes the form fully functional.

I appreciate your help tremendously. Unfortunately, the only issue now is that the form just doesn't really seem any faster than before, once there is a lot of data entered. I am attaching the revised form, into which I have imported actual XML data from last month. If you check it out, you can see that when you add a line, it take several seconds, selecting a client name takes even longer, and tabbing to the quantity columns to enter amounts is also still slow. I'm worried that I may just have to scrap using PDF altogether for this type of data. Maybe there's just too many calculations firing for a PDF to handle this efficiently.

Your thoughts?

Jo

Avatar

Level 10

Hi,

So you are saying that the operation was successful but the patient died.

Try this form, it's still slow but then most things are on my old computer, hopefully yours is not eight years old and it runs ok for you.

https://sites.google.com/site/livecycledesignercookbooks/home/Log_Sheet.modified.3.pdf?attredirects=...

I have made the following changes;

  • Move the code back into the columns under repTotalTotals, and teamTotals, so only the calculations that need to be done are executed.
  • Added a variable to the ItemSet subform (called ClientCode).  This is updated by the Client dropdown and used by the calculate scripts, but variables aren't added to the calculation dependency list so selecting a client doesn't cause the whole form to re-calculate.
  • The team calculation script only looks at the Client/Rep totals (not the individual ItemSet rows), if I understand the form correctly this should be ok and cuts out a lot of rows.
  • Moved the lineNo value calculation from the layout:ready event to the calculate event.  layout:ready is called pretty much when anything happens anywhere on the form.

The scripts are now in a script object (called "Script"), so if it is still too slow and you want to go with a "calculate button", the code in the click event would just be a series of calls to the, e.g.

teamTotals.teamCorrespTotal.rawValue = Script.CalcTeamTotals(P1, "correspTotal", "correspTotal");

Hope it helps this time.

Regards

Bruce

Avatar

Level 4

Hi Bruce. Yes, unfortunately, the patient did not make it! On my computer, it also still runs slowly. I can see a slight improvement, but I'm sure the users of the form will still not be satisfied with the delays.

I think I would like to proceed with your suggestion of making the calls to the script with a calculate button. I will work on this over the next couple of days and see if I can get that to work. I think the users would be ok with the totals not updating immediately as long as they are able to move through the form more quickly.

Thank you so very much for all your help! I'll keep you posted on how it goes.

Jo