Error

47 views
Skip to first unread message

Ian Boskip

unread,
Nov 30, 2021, 12:17:27 AM11/30/21
to Jam.py Users Mailing List
Hi All,

Any idea what this error might mean?

image.png

Ian Boskip

unread,
Nov 30, 2021, 1:47:34 AM11/30/21
to Jam.py Users Mailing List
I've found my mistake :)

Can't do calculation with a field valued as 'null'.


Andrew Yushev

unread,
Dec 1, 2021, 1:44:30 PM12/1/21
to Ian Boskip, Jam.py Users Mailing List
Ian, this error means that there is a looping code, infinite loop.
I have to see the code to say anything definite.

вт, 30 нояб. 2021 г. в 09:47, Ian Boskip <ian.b...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/CAF5bU%3Dq1fCE8ASPoA9QasfMMdwBPf5XAaS_hwZdCKSj2xVMJDg%40mail.gmail.com.

Ian Boskip

unread,
Dec 1, 2021, 6:35:35 PM12/1/21
to Andrew Yushev, Jam.py Users Mailing List
Hi Andrew,

I have this function;

function on_field_changed(field) {
    var item = field.owner;
        calc(item);
}

This was the function throwing the error;

function calc(item) {
    item.result.value = Math.round(item.parameter1.lookup_value / (item.parameter2.lookup_value * item.parameter3.lookup_value * (item.parameter4.value / 1000)));
}

When I changed it to this it worked fine;

function calc(item) {
    if (item.parameter1.lookup_value !== null && item.parameter2.lookup_value !== null && item.parameter3.lookup_value !== null && item.parameter4.value !== null) {
        item.result.value = Math.round(item.parameter1.lookup_value / (item.parameter2.lookup_value * item.parameter3.lookup_value * (item.parameter4.value / 1000)));
    }
}

Andrew Yushev

unread,
Dec 4, 2021, 11:08:14 AM12/4/21
to Ian Boskip, Jam.py Users Mailing List
Ian, this can happen in the on_field_changed event handler when you change the value of some field. 
This change in its turn generates the on_field_changed event that again changes some field and so on.
To prevent this from happening, it is better to use conditions on fields that have changed, for example:

function on_field_changed(field, lookup_item) {
    let item = field.owner;
    if (field.field_name === 'quantity' || field.field_name === 'unitprice') {
        item.amount.value = item.round(item.quantity.value * item.unitprice.value, 2);
        item.tax.value = item.round(item.amount.value * item.owner.taxrate.value / 100, 2);
        item.total.value = item.amount.value + item.tax.value;
    }
}

or the following algorithm can be used:

let calculating;

function on_field_changed(field, lookup_item) {
     if (!calculating) {
        calculating = true;
        try {
             // some calculations 
        }
        finally {
            calculating = false;
        }
    }
}

чт, 2 дек. 2021 г. в 02:35, Ian Boskip <ian.b...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages