set a lookup field as unique

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 206
Joined: 2019-04-30 17:37

set a lookup field as unique

Post by fgazza » 2020-11-17 15:42

Hi to all,

i need to set a lookup field as unique to prevent the creation of two records with the same value in a lookup field by also showing a custom error if the field contains a value already present in another record.

Unfortunately appgini don't allow to check the option "unique" directly in appgini tool and if I attempt to do it appgini give an error when I go to generate the app (erros is "a field cannot be a foreign key and a unique field at the same time").

So I'm asking if you can help me with the code to put in hooks file or -dv.js file to prevent the creation of two records with the same value in a lookup field by also showing a custom error if the field contains a value already present in another record of that tabel.

Thank you so much!

Fabiano

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

Re: set a lookup field as unique

Post by pbottcher » 2020-11-17 18:58

Hi,

do you need the lookup table to contain every possible option, or woud it not be better to only show the available options?
If the later makes sens for you, you could adjust the lookup sql to exclude the already existing entries.
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.

fgazza
Veteran Member
Posts: 206
Joined: 2019-04-30 17:37

Re: set a lookup field as unique

Post by fgazza » 2020-11-17 20:36

Hi and thanks! The idea to only show the available options sounds great.
Would you be kind enough to offer me a code simulation?

Thank you so much!

Post Reply