Set value from other table in Lookup Field for a new Record

Questions related to using nuBuilder Forte.

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 5:38 pm

That's the right place. I just wanted to know if $l->auf_fahrzeug contains an array of values (multiple values).

That means we'd have to change this bit somehow to work with an array:

Code: Select all
$('#$auf_fahrzeug  option[value="'+$('#rech_fahrzeug_temp').val()+'"]').prop("selected", true);
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 6:17 pm

Try this to transfer the values from the temp field rech_fahrzeug_temp to auf_fahrzeug :

Code: Select all
var e = $('#auf_fahrzeug');
var element = e[0];
var values = JSON.parse($('#rech_fahrzeug_temp').val());
for (var i = 0; i < element.options.length; i++) {
    element.options[i].selected = values.indexOf(element.options[i].value) >= 0;
}
e.change();
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby oli » Fri Apr 09, 2021 6:26 pm

I got following error:

Code: Select all
VM3933:4 Uncaught TypeError: Cannot read property 'options' of undefined
    at eval (eval at nuPopulateLookup (nuform.js?ts=20210409083454:2972), <anonymous>:4:29)
    at nuPopulateLookup (nuform.js?ts=20210409083454:2972)
    at successCallback (nuajax.js?ts=20210409083454:589)
    at Object.success (nuajax.js?ts=20210409083454:17)
    at c (jquery.js?ts=20210409083454:2)
    at Object.fireWith [as resolveWith] (jquery.js?ts=20210409083454:2)
    at l (jquery.js?ts=20210409083454:2)
    at XMLHttpRequest.<anonymous> (jquery.js?ts=20210409083454:2)
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 6:40 pm

If you run this in the Developer Console, it should output a 1

Code: Select all
$('#auf_fahrzeug').length
or the object id is invalid/cannot be found
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby oli » Fri Apr 09, 2021 6:57 pm

kev1n wrote:If you run this in the Developer Cnsole, it should output a 1
Code: Select all
$('#auf_fahrzeug').length
or the object id is invalid/cannot be found


sorry ... too stupid to see that the right object id is "rech_fahrzeug" instead of "auf_fahrzeug".
After changing it, it works perfect!

Thank you.

One last question :oops:

On the same form I have the lookup for Customers (kunde) which will be also pre-filled by the selected "auftrag".
Actually "kunde" should be mandatory. Therefore I changed the validation of the lookup field to "No Blanks".
Unfortunately the value on the lookup field will be set after the "No Blanks" check. Therefore I always get the message "KUNDE cannot be left blank".

The Value on Kunde will be also set by following code on After Browse of Lookup "Auftrag":
Code: Select all
nuSetFormValue("rech_kunde", $l->auf_kunde);
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 7:14 pm

Code: Select all
Unfortunately the value on the lookup field will be set after the "No Blanks" check. ".


Why is it set after the check? The check is only done when hitting Save.
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby oli » Fri Apr 09, 2021 7:26 pm

If the field is NOT set as "No Blanks":
    1. Create a new Record "Rechnung"
    2. Select a "Auftrag" on Form "Rechnung" ("Kunde" is still empty)
    3. Save new Record "Rechnung" and the "Kunde" will be filled from the selected "Auftrag"

But if the KUNDE field is defined as "No Blanks" I get the message "KUNDE cannot be left blank" and the record cannot be saved.
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 7:52 pm

Will 'Kunde' not be populated as soon as it has been picked from the lookup?

Code: Select all
3. Save new Record "Rechnung" and the "Kunde" will be filled from the selected "Auftrag"
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby kev1n » Fri Apr 09, 2021 7:57 pm

Do you have the possibility to record it with a screenrecorder (you could use this Chrome Extension), then upload it to e.g. https://streamable.com/ and share the link with me (you can send me a private message if you want).
Then I will understand better how it works
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Set value from other table in Lookup Field for a new Rec

Unread postby oli » Fri Apr 09, 2021 8:21 pm

I already sent you a PM.
But just to be sure: Here's the link to the video : https://streamable.com/6jbr07
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 13 guests