Insert datda from other table

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
meickert
Posts: 15
Joined: 2016-06-24 23:05

Insert datda from other table

Post by meickert » 2021-02-22 10:06

Hi,
I guess this is discussed already somewhere else but I didn't found it :(

I have 2 tables

Kultur
- id
- Kultur_Auswahl (Lookup: db_Kultur.Kultur_VTitel)
- Kultur_Text (html)

and

db_Kultur
- id
- Kultur_VTitel (vchar)
- Kultur_Vorlage (html - contains template datasets to be copied to Kultur.Kultur_Text - see below)

How can I realize this:
In "Kultur" I want to add new data. Therefore I select Kultur_Auswahl (lookup) and Kultur_Text is filled with a copy of db_Kultur.Kultur_Vorlage. By saving the "Kultur"-Dataset the data in "sb_Kultur" shouldn't be touched.

I thought this could (somehow) be done by hooks on update events?

Could someone help me?

Regards
Marcus

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-02-22 10:38

Kultur.Kultur_Text should stay editable to add additional information

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

Re: Insert datda from other table

Post by pbottcher » 2021-02-22 16:23

Hi,

you can use the after_insert hook to add the data from the db_Kultur.Kultur_Vorlage to the Kultur.Kultur_Text.

The only drawback is that you need to save the record after selecting the Kultur_Auswahl.

If you want to make it more flexible and handle the changes to the Kultur_Auswahl field, you can use the before_update hook to realize that.

Not sure what you mean by
the data in "sb_Kultur" shouldn't be touched.
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.

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-02-22 18:03

Are you german? (because of the "ö" in your name...)

If so...

Ich wollte eigentlich damit sagen, dass der Eintrag aus der eigentlichen Tabelle nicht geändert werden soll. Wenn ich "nur ein lookup" benutze und ändere dann etwas, wird ja die Ursprungstabelle geändert. Ich hätte gerne den Datensatz aus der zweiten Tabelle nach der Auswahl in die erste kopiert, verstehe aber nicht ganz, wie das funktionieren soll.

Gruß
Marcus

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

Re: Insert datda from other table

Post by pbottcher » 2021-02-22 20:15

hi,
as this forum is in english, let's stick to it.

The fleld Kultur_Text needs to be a normal field. In the before_insert function you set the data to the template
something like

Code: Select all

$data['Kultur_Text']=sqlvalue("select Kultur_Vorlage from db_Kultur where id={$data['Kultur_Auswahl']}");
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.

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-02-23 06:46

Hi,
thanks that nearly worked... thanks,.. but when I try to change the text in Kultur_Text and click on save.... I got a message that the changes couldn't be done.

For explanation. After the text is copied from Kultur_Vorlage to Kultur_Text, I want the Kultur_Text to be editabke. The changes should only applied to Kultur_Text but not to Kulur_Vorlage. Is this possible?

Regards
Marcus

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

Re: Insert datda from other table

Post by pbottcher » 2021-02-23 07:12

Hi Marcus,

how are the fieldsetting in AppGini for that field? If it is a normal field, you should be able to edit the field.
Maybe you can post a screenshot.
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.

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-02-23 07:32

Image
Image
Image
Image
Image

It works until I try to save my changes to Kulture_Text
Attachments
00.PNG
00.PNG (6.09 KiB) Viewed 3501 times

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Insert datda from other table

Post by onoehring » 2021-02-23 17:00

Hi,

isn't there a problem with your suggestion pbötcher? If there is more than the field "Kultur Text" and there are changes to another field, the line of code you suggested will pull the "Beispieltext" again (if there is a value set). Maybe it should be checked first, if "Beispieltexte" holds a value and only then replace the text in "Kultur Text" (or even append to that). Appending would allow composing a "Kultur Text" from different "Beispieltexte"

I noticed a problem in AG 5.92 (still exists in 5.94): viewtopic.php?f=11&t=4085 which might be involved in the problem you are having: As your "Beispieltexte" is not required, it might hold {empty_value} and thus fail some SQL.
Just a thought

Olaf

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

Re: Insert datda from other table

Post by pbottcher » 2021-02-23 20:24

Hi,

@Olaf:
this is not the 100% solution, it shall give a startingpoint. As the description of the question is give with only partial information, the solution may not be perfect.

@Marcus,
can you post your hooks/kultur.php ? Is there any other code in that hook?
I tested the feature on my testsystem and it just works fine.
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.

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-02-24 19:35

Hi,

@pböttcher. I tried to generate the files again to a new fresh directory and than it worked. So thanks for your help!

meickert
Posts: 15
Joined: 2016-06-24 23:05

Re: Insert datda from other table

Post by meickert » 2021-03-05 23:03

Hi together... now I have another problem :(

I added a checkbox called "Zeige_Vorlage". When it is unchecked the Beispieltext-Dropdown (Programm_Vorlage in AG) is not shown and if checked Beispieltext-Dropdown is shown. Checking and unchecking is working well with my programm-dv.js hook which I found elsewhere in the forum here.

I made an entry in the before_insert hook:
$prog1 = $_GET['Progrann_Vorlage'];
if ((!isset($prog1)) || ($prog1 != NULL)){
$data['Prozess']=sqlvalue("select Prozess from db_programm where id={$data['Programm_Vorlage']}");
$data['Programm_Vorlage'] = NULL;
return TRUE;
and in the before_update hook:
$prog1 = $_GET['Programm_Vorlage'];
if ('Programm_Vorlage' != NULL)
$data['Prozess']=sqlvalue("select Prozess from db_programm where id={$data['Programm_Vorlage']}");
$data['Programm_Vorlage'] = NULL;
return TRUE;
and it gets the correct selected templates in the field "Prozess" on saving. But when I try to change the text in "Prozess" and click on "save" I get the data from the origin template. Also on a new dataset when I don't click the checkbox to use a template and edit "Prozess" whith individual data, there is only saved a "NULL" on "Prozess".

What I want is a dropdown field, which is only shown when the checkbox "Zeige_Vorlagen" is checked. And when it is checked I would like to select a text template from the dropdown which fills my other fields (like my first posting above) upon saving. I don't now if I'm using the "if clauses" right?

Could someone help me? Maybe @pböttcher because your tip above worked fine :)

Regards
Marcus

Post Reply