Welcome to the nuBuilder Forums!

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

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

Questions related to using nuBuilder Forte.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

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: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

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();
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

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

Unread post by oli »

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

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

Unread post by kev1n »

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
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

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

Unread post by oli »

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

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

Unread post by kev1n »

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.
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

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

Unread post by oli »

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

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

Unread post by kev1n »

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: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

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
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

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

Unread post by oli »

I already sent you a PM.
But just to be sure: Here's the link to the video : https://streamable.com/6jbr07
Post Reply