Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How to transfer the value of a lookup field?

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

How to transfer the value of a lookup field?

Unread post 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?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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?
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

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

Unread post 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.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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')

kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

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

Unread post 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
    }
}
Post Reply