Page 1 of 1

How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-06 00:51
by zibrahim
Hi there,
I am wondering if anyone has some idea how to retrieve a pre-defined or pre-selected lookup field ID in AppGini.
Let me explain...
When you want to add a new record from a child table (in DV) with Add New button like this...
SCR-20240906-iclw.png
SCR-20240906-iclw.png (61.06 KiB) Viewed 13049 times
a modal window will appear with the lookup field pre-defined or pre-selected with the parent record value...like this
SCR-20240906-icur.png
SCR-20240906-icur.png (67.87 KiB) Viewed 13049 times
How can I retrieve the ID of the pre-defined lookup field in javascript?
Thanking you in advance.

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-08 21:29
by pbottcher
Hi Zala,

did you try

Code: Select all

$j('[name="SelectedID"]').val()

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-08 23:48
by zibrahim
Yes I tried, but nothing returned. I believe it is because the record is not created yet because it is initiated from Add New button from the child tab.

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-09 14:26
by ppfoong
In a multiuser environment, you won't know the running number before record is created, unless you lock the table.

Normally I just make the field non-required, leave it blank, and add in the value right after insert (in the hook's after insert portion).

Alternatively, you can use the running number from another table. When init, you insert a record of that table to get the number. However, there will be unused running number in case you don't save the new record.

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-09 14:29
by ppfoong
In a single user environment, you can use SQL select max to get the current maximum running number, then +1 to it.

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-09 22:05
by zibrahim
Let me explain again, i am not looking for the id of the child, but the parent

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-10 04:18
by ppfoong
zibrahim wrote:
2024-09-09 22:05
Let me explain again, i am not looking for the id of the child, but the parent
Hmm... you can take a look at this:
https://forums.appgini.com/phpbb/viewtopic.php?t=1831

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-10 04:23
by ppfoong

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-10 09:07
by zibrahim
Hi ppfoong,
thanks for the suggestions. However, they did not answer my question, yet

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-10 13:30
by jsetzer
When the modal is being opened, there should be request parameters named something like:

filterer_FIELDNAME

...for example (depending on your table) filterer_client_id=17&filterer_account_id=423

Maybe this is what you are looking for.

This should work for lookups, if modeled correctly in parent-children settings of master-table.

Re: How to retrieve pre-defined lookup ID in javascript

Posted: 2024-09-11 04:37
by zibrahim
Yes!! Thank you so much Jan.