How to retrieve pre-defined lookup ID in javascript

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
zibrahim
Veteran Member
Posts: 165
Joined: 2020-01-28 18:30
Location: Malaysia

How to retrieve pre-defined lookup ID in javascript

Post by zibrahim » 2024-09-06 00:51

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 6688 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 6688 times
How can I retrieve the ID of the pre-defined lookup field in javascript?
Thanking you in advance.
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1700
Joined: 2018-04-01 10:12

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

Post by pbottcher » 2024-09-08 21:29

Hi Zala,

did you try

Code: Select all

$j('[name="SelectedID"]').val()
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
zibrahim
Veteran Member
Posts: 165
Joined: 2020-01-28 18:30
Location: Malaysia

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

Post by zibrahim » 2024-09-08 23:48

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.
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

ppfoong
Veteran Member
Posts: 62
Joined: 2021-07-13 16:46

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

Post by ppfoong » 2024-09-09 14:26

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.

ppfoong
Veteran Member
Posts: 62
Joined: 2021-07-13 16:46

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

Post by ppfoong » 2024-09-09 14:29

In a single user environment, you can use SQL select max to get the current maximum running number, then +1 to it.

User avatar
zibrahim
Veteran Member
Posts: 165
Joined: 2020-01-28 18:30
Location: Malaysia

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

Post by zibrahim » 2024-09-09 22:05

Let me explain again, i am not looking for the id of the child, but the parent
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

ppfoong
Veteran Member
Posts: 62
Joined: 2021-07-13 16:46

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

Post by ppfoong » 2024-09-10 04:18

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


User avatar
zibrahim
Veteran Member
Posts: 165
Joined: 2020-01-28 18:30
Location: Malaysia

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

Post by zibrahim » 2024-09-10 09:07

Hi ppfoong,
thanks for the suggestions. However, they did not answer my question, yet
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1926
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

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

Post by jsetzer » 2024-09-10 13:30

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

User avatar
zibrahim
Veteran Member
Posts: 165
Joined: 2020-01-28 18:30
Location: Malaysia

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

Post by zibrahim » 2024-09-11 04:37

Yes!! Thank you so much Jan.
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

Post Reply