if that field says X, make this field default Y

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
graham
Veteran Member
Posts: 86
Joined: 2020-09-29 12:30

if that field says X, make this field default Y

Post by graham » 2020-10-08 13:04

Hi everyone - I'm new so hello!
I'm setting a field called Group to one of the default options: <%%creatorGroup%%>
I have another field in the same table - Country - which I want to auto populate with a choice that depends on what goes in the Group field.
In other words, say the <%%creatorGroup%%> throws up 'UK Editor' in the Group field, I want the Country field to say 'UK'
If the <%%creatorGroup%%> throws up 'France Editor' in the Group field, I want the Country field to say 'France'. And so on.
Can anyone help with how to do this?
Thanks in advance.

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

Re: if that field says X, make this field default Y

Post by pbottcher » 2020-10-08 19:22

Hi,

you could use the after_insert hook for that. Update the just inserted record according to your logic for the Group field.

It depends where you want to hold your mapping fo UK Editor -> UK, France Editor -> France , etc.
Either create a separate table for that (so you can retrieve the matching entry), or if is always the first word of the group, you could use PHP to extract the necessary information and insert accordingly
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.

graham
Veteran Member
Posts: 86
Joined: 2020-09-29 12:30

Re: if that field says X, make this field default Y

Post by graham » 2020-10-09 13:02

Thank you.
I have a table 'meetings' with a field 'group' <%%creatorGroup%%> and a field 'insert_field'. (I'm trying to autopopulate 'insert-field' with something depending on what's entered in 'group'.) I created a table 'country' with two fields - 'group' (UK Editor) and 'show' (UK)
Then went to the after_insert hook area in the hooks/meetings.php. And I'm trying to put a SQL statement in their but can't seem to get it right. I tried lots but for example ..
INSERT INTO meetings.insert_field
SELECT show FROM country
WHERE group=meetings.group;
Am I at least on the right track?
Thanks.

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

Re: if that field says X, make this field default Y

Post by pbottcher » 2020-10-10 06:34

Hi,

yes you are, you should add the selected row in your statement.
Something like

WHERE group=meetings.group and id=$data['id']

assuming your PK is id.
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.

Post Reply