How to transfer the value of a lookup field?

Questions related to customising nuBuilder Forte with Javascript or PHP.

How to transfer the value of a lookup field?

Postby kknm » Tue Oct 13, 2020 11:04 pm

There are several subforms on the form with the same lookup fields. After filling in one of the subforms by one performer, another performer, based on this subform, fills in another subform using a button on this form and js-script. Lines and numbers wrap normally when iterating over rows in the first subform. How to transfer the value of a lookup field?
kknm
 
Posts: 154
Joined: Sat Apr 11, 2020 7:33 am

Re: How to transfer the value of a lookup field?

Postby kev1n » Wed Oct 14, 2020 12:53 pm

Hi,

I'm afraid I don't undestand your question/what you are trying to do. Can you add some screenshots and maybe describe it in a different way?
If you like nuBuilder, please leave a review on SourceForge

nuBuilder Code Library (82)
Installation Guides
Updating nuBuilder

Join Discord to talk about nuBuilder!
kev1n
 
Posts: 1084
Joined: Mon Oct 15, 2018 2:13 am

Re: How to transfer the value of a lookup field?

Postby kknm » Mon Oct 19, 2020 12:41 am

kev1n wrote:Hi,

I'm afraid I don't undestand your question/what you are trying to do. Can you add some screenshots and maybe describe it in a different way?


Initially, all forms are empty. After weighing, the right form is automatically filled in, which only knows the driver and the weight. At the end of the shift, the left form must be detailed by the dispatcher based on the data from the right form.
Attachments
Main_form.png
Main_form.png (72.25 KiB) Viewed 167 times
kknm
 
Posts: 154
Joined: Sat Apr 11, 2020 7:33 am

Re: How to transfer the value of a lookup field?

Postby kev1n » Mon Oct 19, 2020 3:19 am

Try the subformsCopyDriver() function:

Code: Select all
subformsCopyDriver('idSfSource', 'idColDriverSource', 'idNoSource', 'objSfDest', 'idColDriverDest', 'idNoDest')


Replace the parameters with the corresponding IDs of your subforms / fields, where:

Right Subform (Source):

idSfSource: Object Id of your source subform
idColDriverSource: Object Id your driver column
idNoSource: Object Id your № column

Left Subform (Destination)
objSfDest: Object Id of your destination subform
idColDriverDest: Object Id your driver column
idNoDest: Object Id your № column


Code: Select all

function subformsCopyDriver(idSfSource, idColDriverSource, idNoSource, objSfDest, idColDriverDest, idNoDest) {

    var objSource = nuSubformObject(idSfSource);
    var colDriverSource = objSource.fields.indexOf(idColDriverSource);
   var colNoSource = objSource.fields.indexOf(idNoSource);
   

    var objDest = nuSubformObject(objSfDest);
    var colDriverDest = objDest.fields.indexOf(idColDriverDest);
   var colNoDest = objDest.fields.indexOf(idNoDest);
   
    for (var s = 0; s < objSource.rows.length; s++) {
   
        if (objSource.deleted[s] == 0) {
            var valColDriverSource = objSource.rows[s][colDriverSource];
         var valColNoSource = objSource.rows[s][colNoSource];
   
      for (var d = 0; d < objDest.rows.length; d++) {
         
         if (objSource.deleted[d] == 0) {
            
            var valColDriverDest = objSource.rows[d][colDriverDest];
            var valColNoDest = objSource.rows[d][colNoDest];

            if (valColNoSource == valColNoDest) {
               
               let destObjId = objSfDest + nuPad3(d) + idColDriverDest;
               if ($('#' + destObjId).val() == '') {
                  nuGetLookupId(valColDriverSource, destObjId);
               }

            }
         
         }
         
      }
              
        }
    }

}

subformsCopyDriver('subform','sub_field02','sub_field00','subform','sub_field07','sub_field01')

If you like nuBuilder, please leave a review on SourceForge

nuBuilder Code Library (82)
Installation Guides
Updating nuBuilder

Join Discord to talk about nuBuilder!
kev1n
 
Posts: 1084
Joined: Mon Oct 15, 2018 2:13 am

Re: How to transfer the value of a lookup field?

Postby kknm » Wed Oct 21, 2020 4:38 pm

kev1n wrote:Try the subformsCopyDriver() function:

Code: Select all
subformsCopyDriver('idSfSource', 'idColDriverSource', 'idNoSource', 'objSfDest', 'idColDriverDest', 'idNoDest')


Replace the parameters with the corresponding IDs of your subforms / fields, where:

Right Subform (Source):

idSfSource: Object Id of your source subform
idColDriverSource: Object Id your driver column
idNoSource: Object Id your № column

Left Subform (Destination)
objSfDest: Object Id of your destination subform
idColDriverDest: Object Id your driver column
idNoDest: Object Id your № column


Code: Select all

function subformsCopyDriver(idSfSource, idColDriverSource, idNoSource, objSfDest, idColDriverDest, idNoDest) {

    var objSource = nuSubformObject(idSfSource);
    var colDriverSource = objSource.fields.indexOf(idColDriverSource);
   var colNoSource = objSource.fields.indexOf(idNoSource);
   

    var objDest = nuSubformObject(objSfDest);
    var colDriverDest = objDest.fields.indexOf(idColDriverDest);
   var colNoDest = objDest.fields.indexOf(idNoDest);
   
    for (var s = 0; s < objSource.rows.length; s++) {
   
        if (objSource.deleted[s] == 0) {
            var valColDriverSource = objSource.rows[s][colDriverSource];
         var valColNoSource = objSource.rows[s][colNoSource];
   
      for (var d = 0; d < objDest.rows.length; d++) {
         
         if (objSource.deleted[d] == 0) {
            
            var valColDriverDest = objSource.rows[d][colDriverDest];
            var valColNoDest = objSource.rows[d][colNoDest];

            if (valColNoSource == valColNoDest) {
               
               let destObjId = objSfDest + nuPad3(d) + idColDriverDest;
               if ($('#' + destObjId).val() == '') {
                  nuGetLookupId(valColDriverSource, destObjId);
               }

            }
         
         }
         
      }
              
        }
    }

}

subformsCopyDriver('subform','sub_field02','sub_field00','subform','sub_field07','sub_field01')


Oddly enough, I found an easier way ...
Code: Select all
function zapoln_is_ves(event) {
   
    var sour = nuSubformObject('sub_ves');

    var r = sour.rows;
   
    for (var i = 0; i <r.length-1; i ++) {
        nuAddRow('sub_hodki');

    $('#sub_hodki' + nuPad3(i) + 'hod_num').val(r[i][1]).change();
    $('#sub_hodki' + nuPad3(i) + 'hod_kol').val(r[i][2]).change();
    $('#sub_hodki' + nuPad3(i) + 'hod_avg').val(r[i][4]).change();
    $('#sub_hodki' + nuPad3(i) + 'hod_vod').val(r[i][7]).change();    //This is a lookup field
    }
}
kknm
 
Posts: 154
Joined: Sat Apr 11, 2020 7:33 am


Return to Custom Code