How to programmatically add items to a table

149 views
Skip to first unread message

Simone Fabris

unread,
Feb 22, 2021, 8:04:44 AM2/22/21
to Jam.py Users Mailing List
Helli,
first of all, thank for this amazing piece of software.

I would like to ask how to "programmatically" add items (rows) to a table (sorry if I'm not using the correct jam-py terminology here):

This is how far I can get:

  btn_sched.click(function (){
      if (item.scheda_di_controllo.value !== null) {
        let schede = task.prove_scheda_controllo.copy();
        schede.open({where: {master_rec_id: item.scheda_di_controllo.value} }, function(){
            schede.each(function(rec) {
                item.details.Risultati.open();
                item.details.Risultati.append();    
                item.details.Risultati.prova.value = rec.prova.value;
                item.details.Risultati.cicli.value = rec.cicli.value;
                item.details.Risultati.limite_matrice.value = rec.risultato_matrice.value;
                item.details.Risultati.limite_pelle.value = rec.risultato_pelle.value;
                item.post();
                
            });
        });
      }
  });

So I want to add some records from "scheda_di_controllo" to the details of the open table.

The code I posted "sort of" works: only the first row is added, on the following rows I get this exemption:

Uncaught Item Risultati - can't append record: master item is not in edit or insert state

Here I'm stuck... 
If context of the problem is not enough clear I will post more details.

Thanks

Simone

Dražen Babić

unread,
Feb 22, 2021, 8:29:17 AM2/22/21
to Jam.py Users Mailing List
Thanks

Not sure whats happening with the users from a shoe looklike country, but there are many :)

Pls try to explain the context why, and not how? 
Maybe *how* cant be done but *why* might, in some way...

Thx
D.



--
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/e0b32ead-3a41-4260-be62-21b990ffdf78n%40googlegroups.com.

Simone Fabris

unread,
Feb 22, 2021, 8:59:49 AM2/22/21
to Jam.py Users Mailing List
Thanks for the extra fast reply.

The logic underneath is this (so "why"):
 - Journal is made by Samples, details are "lab tests" of each sample. Lab tests are "test /  expected value / recorded value"
 -  Each sample have a "requirement" specified.  For each "requirement" I have a "control chart". Control chart is the details. Control chart is composed from "test / expected value"

So what I'm trying to do is:
- if the user need, he can attach the details (lab tests) of samples, based on the match between "sample - requirement / requirement - control chart"

I can't attach a sample right now, as table naming are a big mess. However I could prepare  a sample with proper table names as soon as I have some spare time.

Regards from the shoe looklike country!

Simone

Dražen Babić

unread,
Feb 22, 2021, 9:10:36 AM2/22/21
to Jam.py Users Mailing List
Thanks for the clarification.
Hopefuly Andrew might pickup since Jam is mainly used in medicine industry.

D.


Andrew Yushev

unread,
Feb 22, 2021, 2:43:50 PM2/22/21
to Dražen Babić, Jam.py Users Mailing List
Hi, Simone

Can you specify what you want to do.
It is hard to understand it from the code.

Regards,
Andrew Yushev


пн, 22 февр. 2021 г. в 17:10, Dražen Babić <bab...@gmail.com>:

Drazen D. Babic

unread,
Feb 25, 2021, 8:35:27 PM2/25/21
to Jam.py Users Mailing List
Maybe try to record a movie of the current system if you have one.
D.

Simone Fabris

unread,
Mar 8, 2021, 11:05:16 AM3/8/21
to Jam.py Users Mailing List
Oh my god... I just realized that I wrote directly to Andrew without forwarding the message to the mailing list.
Andrew solved my problem, here is the code snippet:

The code could be as follows:

function on_edit_form_created(item) {
    var button =  item.add_edit_button('Press Me', {parent_class_name:'form-footer' });
    button.click(function() {
        add_details(item);        
    });
}

function add_details(item) {
    let requirements = task.customer_requirements.copy();
    if (!item.customer_requirement.value) {
        item.alert('Customer requirements are not specified.');
        return;
    }
    requirements.set_where({customer_requirement: item.customer_requirement.value});
    requirements.open(function(r) {
        r.requirements_control_chart.open(function(chart) {
            chart.each(function(c) {
                item.samples_test.append();
                item.samples_test.phisicalproperty.value = c.phisicalpropery.value;                
                item.samples_test.phisicalproperty.lookup_value = c.phisicalpropery.lookup_value;
                item.samples_test.maximum_permitted_value.value = c.maximum_value.value;
                item.samples_test.minimum_permitted_value.value = c.minimum_value.value;
                item.samples_test.post();
            });
        });    
    });
}


With this code everything is working! The problem in my code was that I was doing: item.post() and not item.samples_test.post()


Regards,

Simone

Drazen D. Babic

unread,
Mar 9, 2021, 11:47:41 PM3/9/21
to Jam.py Users Mailing List
Hi, 
would you be able to demonstrate this with a few photos for general audience? They say one pic replaces 1000 words :)
Thanks in advance
Message has been deleted

Simone Fabris

unread,
Mar 11, 2021, 3:41:59 PM3/11/21
to Jam.py Users Mailing List
I can do more :-) 
Here is a video: https://youtu.be/F9654cddOgw

And also the really small example. With the example you can follow the video.


Regards,

Simone
Reply all
Reply to author
Forward
0 new messages