Page 2 of 2

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

Posted: Fri Apr 09, 2021 10:08 am
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);

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

Posted: Fri Apr 09, 2021 10:47 am
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();

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

Posted: Fri Apr 09, 2021 10:56 am
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)

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

Posted: Fri Apr 09, 2021 11:10 am
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

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

Posted: Fri Apr 09, 2021 11:27 am
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); 

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

Posted: Fri Apr 09, 2021 11:44 am
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.

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

Posted: Fri Apr 09, 2021 11:56 am
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.

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

Posted: Fri Apr 09, 2021 12:22 pm
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"

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

Posted: Fri Apr 09, 2021 12:27 pm
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

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

Posted: Fri Apr 09, 2021 12:51 pm
by oli
I already sent you a PM.
But just to be sure: Here's the link to the video : https://streamable.com/6jbr07