Selecting a lookup / drop down

33 views
Skip to first unread message

Moh. Sarip Hidayat

unread,
Jan 10, 2026, 4:44:43 AM (9 days ago) Jan 10
to Jam.py Users Mailing List
Hello,

I have this table:
image.png

And this code
function on_field_changed(field, lookup_item) {
    let item = field.owner;
    if ( (['order_line_id', 'inspection_type']).includes(field.field_name)) {
        if (item.order_line_id.value && item.inspection_type.value){
            let d = item.task.catalogs.cecc_sample_sizes.copy();
            d.open({where: {
                'min__le': item.actual_batch_size.lookup_value,
                'max__ge': item.actual_batch_size.lookup_value
            }});
            item.batch_size.value = d.id.value;
        }
    }
}
To summarize, if order_line_id or inspection_type has been selected, I would like to automatically select the value for batch_size, which in turn should automatically populate sample_qty.

However, this line seems to do nothing:
item.batch_size.value = d.id.value;
I have tried to use data or lookup_value instead of value, but they did nothing as well.

I also tried adding item.update_controls() after that line but it does nothing as well.

How can I make this work?

Thank you.

Best Regards,
Moh. Sarip Hidayat
Visit my profile website at musahi0128.github.io

Danijel Kaurin

unread,
Jan 10, 2026, 6:53:02 AM (9 days ago) Jan 10
to Moh. Sarip Hidayat, Jam.py Users Mailing List
Hi.

Try this:
function on_field_changed(field, lookup_item) {
    let item = field.owner;

    if (field.field_name === "order_line_id" || field.field_name === "inspection_type") {
        if (field.value){

            let d = item.task.catalogs.cecc_sample_sizes.copy();
            d.open({where: {

                'min__le': parseInt(item.actual_batch_size.display_text),
                'max__ge': parseInt(item.actual_batch_size.display_text)
            }});
            item.batch_size.value = d.id.value;
        }
    }
}
Regards

Danijel

--
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 visit https://groups.google.com/d/msgid/jam-py/CAF0JkBqBEbm3AHyFQRmSa6OgNZFx7%3DrMajvX-Akrku5%2BbT3P9A%40mail.gmail.com.

Moh. Sarip Hidayat

unread,
Jan 10, 2026, 7:45:38 AM (9 days ago) Jan 10
to Jam.py Users Mailing List
Hi Danijel, thank you for your reply.

My apologize, it seems I mistype this part

> To summarize, if order_line_id or inspection_type has been selected
It supposed to be:
To summarize, if order_line_id and inspection_type has been selected

I have no problem with the code except for this line which seems to do nothing, where I expect it to change the lookup value.

item.batch_size.value = d.id.value;

I know the rest of the code is working as expected because if I add console.log(d.id.value); after line 9, it will show the value in the console.

Thank you.

Dean D. Babic

unread,
Jan 10, 2026, 10:07:06 PM (8 days ago) Jan 10
to Jam.py Users Mailing List
https://chatgpt.com/c/69630d0e-b02c-8323-b37e-8878ff3ceb48
and:
function on_after_apply(item) {
item.refresh_record();
}


Moh. Sarip Hidayat

unread,
Jan 11, 2026, 2:46:31 AM (8 days ago) Jan 11
to Dean D. Babic, Jam.py Users Mailing List
Hi Dean, thank you for your reply.

Just letting you know the chat you were sharing is not valid anymore:
image.png

Also to clarify my intent, please review the attached video.


I wish to select the value for the Batch size through the client module's code.
The goal is to minimize users mistakenly selecting a wrong value here and make this field read only.

To give you more context the cecc_sample_sizes table looks like this:
image.png

From the video, the inspection type is Normal (1) and the Actual batch size is 240, so we should be able to determine that the correct selection would be the one with id 3 which the code already did correctly. It just comes down to selecting the value in the UI via the code that I couldn't figure out.

Please let me know if you need further details.

Thank you.

Best Regards,
Moh. Sarip Hidayat
Visit my profile website at musahi0128.github.io

You received this message because you are subscribed to a topic in the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jam-py/XhfMEG5GXNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jam-py+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jam-py/5625dd26-f85d-47df-be81-473360f45728n%40googlegroups.com.

Danijel Kaurin

unread,
Jan 11, 2026, 2:57:20 AM (8 days ago) Jan 11
to Moh. Sarip Hidayat, Dean D. Babic, Jam.py Users Mailing List
Hi.

You need to set lookup value of the field to visualy view the change of field value:

item.batch_size.value = d.id.value;
item.batch_size.lookup_value = d.bach.value;

Dean D. Babic

unread,
Jan 11, 2026, 4:35:08 AM (8 days ago) Jan 11
to Jam.py Users Mailing List
Try:

function on_field_changed(field, lookup_item) {
let item = field.owner;

if (field.field_name === 'actual_batch_size') {

let d = item.task.catalogs.cecc_sample_sizes.copy();

d.open(
{
where: {
'min__le': item.actual_batch_size.value,
'max__ge': item.actual_batch_size.value
}
},
function () {
if (!d.eof()) {
item.batch_size.value = d.id.lookup_value;
} else {
item.batch_size.value = null;
item.alert('No matching sample size found');
}
}
);
}
}

function on_after_apply(item) {
item.refresh_record();
}

Dean D. Babic

unread,
Jan 11, 2026, 5:34:31 AM (8 days ago) Jan 11
to Jam.py Users Mailing List
With your initial JS, 
what V7 is getting is this:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help https://xhr.spec.whatwg.org/#sync-warning jquery.js:9828:9

Which is exactly where the problem is. The below code IS working, but it must 
be asynchronous instead, or a nasty error might happen:

function on_field_changed(field, lookup_item) {
let item = field.owner;
if ( (['actual_batch_size']).includes(field.field_name)) {
if (item.actual_batch_size.value){
let d = item.task.cecc_sample_sizes.copy();
d.open({where: {
'min__le': item.actual_batch_size.value,
'max__ge': item.actual_batch_size.value
}});
item.batch_size.value = d.id.value;
}
}
}
You are testing on_field_changed fields and not actual_batch_size in first test. So when actual_batch_size is out of range, error again.
Try with ie 500!

Also testing twice the same fields but for the value! As Danijel suggested, test them with ie:
if (target_field && field.value)...
Or have the Required turned on, so no need for on_field_changed testing on such fields.
I can't imaging empty field here. Client side testing is expensive. 

Or better, move it to the Server Module.


Message has been deleted

Moh. Sarip Hidayat

unread,
Jan 13, 2026, 2:16:48 PM (6 days ago) Jan 13
to Danijel Kaurin, Dean D. Babic, Jam.py Users Mailing List
Hi Danijel, thank you for your pointer.

I ended up with this code and it works as expected, so thank you very much!

function on_field_changed(field, lookup_item) {
    let item = field.owner;
    if ( (['order_line_id', 'inspection_type']).includes(field.field_name)) {
        if (item.order_line_id.value && item.inspection_type.value){
            let d = item.task.catalogs.cecc_sample_sizes.copy();
            d.open({where: {
                'inspection_type': item.inspection_type.value,
                'min__le': item.actual_batch_size.lookup_value,
                'max__ge': item.actual_batch_size.lookup_value
            }});
            item.batch_size.value = d.id.value;
            item.batch_size.lookup_value = d.batch_size.value;
            item.sample_qty.lookup_value = d.sample_size.value;
        }
    }
}

This shows me that updating the lookup_value will update the visual controls, and updating the value is still needed so it would stay upon save.

Thank you.

Best Regards,
Moh. Sarip Hidayat
Visit my profile website at musahi0128.github.io

Reply all
Reply to author
Forward
0 new messages