Page 1 of 1

How to transfer the value of a lookup field?

Posted: Tue Oct 13, 2020 3:34 pm
by kknm
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?

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

Posted: Wed Oct 14, 2020 5:23 am
by kev1n
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?

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

Posted: Sun Oct 18, 2020 5:11 pm
by kknm
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.

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

Posted: Sun Oct 18, 2020 7:49 pm
by kev1n
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')


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

Posted: Wed Oct 21, 2020 9:08 am
by kknm
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
    }
}