You are viewing limited content. For full access, please sign in.

Question

Question

Forms collection creation time

asked on December 5, 2017

Hi,

I have a form which uses a collection with a large number of fields for each element of the collection.  When I append a new element to the collection it takes a few seconds to create (depending on the processing power of the client/browser being used).  This in itself is not a problem.

However, I have noticed that as additional elements are added to the forms collection, the creation time appears to be increasing linearly each time i.e. when I get to a tenth element it will take ten times longer to be added.  This seemed odd to me until i remembered that I also had a number of reasonably complex formulae within each element.  So i am assuming (the only explanation I can come up with at present) is that the formulae in every element gets recalculated each time an element is added which is what is causing the increased delay with each additional element.

Does anyone know if this explanation makes sense and if so, is there an easy way to prevent recalculation while the element is being created ?  Or perhaps there is another reason for the time increase.

 

TIA,

Ian

 

 

 

0 0

Answer

SELECTED ANSWER
replied on December 7, 2017

Hi Ian,

If you still want to use formula for calculation, you could try the following script and see if calculation result and performance is good. It would restrict that formula calculation only work on the last row of collection/table.

$(document).ready(function(){
  LF.formula.getPopulatedFields = function (populatedFieldId, excludeReadonly, fieldObject) {
        var populatedFields = fieldObject;
        if (!populatedFields) {
            var populatedFields = $("[id='Field" + populatedFieldId + "']");
            if (populatedFields.length === 0) { // table/collection fields are the populated fields
              populatedFields = $("[id^='Field" + populatedFieldId + "(']:last");
            }
        }
        populatedFields = _.filter(populatedFields, function (popField) {
            return ($(popField).attr('lookupAlt') !== "true" || $(popField).attr('readonly') !== "readonly") && // (field doesn't have lookupAlt or it's not readonly), AND
                (!excludeReadonly || !($(popField).prop('backend-readonly') || $(popField).prop('readonly'))); // (readonly is not excluded or it's not readonly)
        });
        return $(populatedFields);
    };
});

However we can't confirm if there is any side effect and if all formula calculation would be correct. 

Another way is to remove formula referring the collection field, and use JavaScript for calculation. To do that, you could refer to https://answers.laserfiche.com/questions/66996/javascript-calculation-for-multi-row-table

 

1 0

Replies

replied on December 6, 2017

Hi Ian,

Formula will be re-calculated if the variable used in formula is updated. So if your formula uses field in this collection, fields in all sets will be re-calculated when adding new sets. That would take some time if you have large number of fields and complex formulae.

There is no easy way to prevent recalculation, and doing that might make formula result incorrect. If performance was too slow for you, can you open a support case and provide your process? Maybe we can do some enhancement in future version.

0 0
replied on December 7, 2017

Thanks Rui,

I can see that recalculation makes sense in many cases.  In my particular application the calculations within each collection can be considered independent and the results will not change with the addition of a new collection, so if there was a way to ensure that the calculation only occurs on the most recently added member of the collection, that would resolve the issue for me.

I am comfortable with a javascript/jquery solution so if "no easy way" includes some code I am happy to get some guidance in this direction.

 

many thanks

 

0 0
SELECTED ANSWER
replied on December 7, 2017

Hi Ian,

If you still want to use formula for calculation, you could try the following script and see if calculation result and performance is good. It would restrict that formula calculation only work on the last row of collection/table.

$(document).ready(function(){
  LF.formula.getPopulatedFields = function (populatedFieldId, excludeReadonly, fieldObject) {
        var populatedFields = fieldObject;
        if (!populatedFields) {
            var populatedFields = $("[id='Field" + populatedFieldId + "']");
            if (populatedFields.length === 0) { // table/collection fields are the populated fields
              populatedFields = $("[id^='Field" + populatedFieldId + "(']:last");
            }
        }
        populatedFields = _.filter(populatedFields, function (popField) {
            return ($(popField).attr('lookupAlt') !== "true" || $(popField).attr('readonly') !== "readonly") && // (field doesn't have lookupAlt or it's not readonly), AND
                (!excludeReadonly || !($(popField).prop('backend-readonly') || $(popField).prop('readonly'))); // (readonly is not excluded or it's not readonly)
        });
        return $(populatedFields);
    };
});

However we can't confirm if there is any side effect and if all formula calculation would be correct. 

Another way is to remove formula referring the collection field, and use JavaScript for calculation. To do that, you could refer to https://answers.laserfiche.com/questions/66996/javascript-calculation-for-multi-row-table

 

1 0
replied on December 8, 2017 Show version history

Thank you Rui that is very helpful.  I'll experiment with your script. 

We'd like to avoid moving all the calculations to javascript as there are many of them within the collection fields and it is much easier to make edits to the formulae rather than to scripts.  However, that is an alternative solution if we don't get mileage via the script you have provided.

 

many thanks,

Ian

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.