Set a Mutator field at Insert

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Set a Mutator field at Insert

Post by RonP » 2013-08-29 11:45

Hi,
I'm using in a table the following fields: Mutator and Creator (both Varchr).

When I insert a record I would like to set de Mutator field = Creator Field
I'm already using the automatic value for these fields: <%%editorUsername%%> and <%%creatorUsername%%>
This works well after I edit the record but I also want to fill field Mutator at an Insertion.

If I put this code in de Hooks file I don't see any result

Code: Select all

function acties_after_insert($data, $memberInfo, &$args){
	// record mutator = creator
	$data['Mutator'] = $memberinfo['MemberId'];
		return TRUE;
	}
What do I miss?

Thanks in advance

Ron

albuchholz
Posts: 10
Joined: 2013-06-04 21:26

Re: Set a Mutator field at Insert

Post by albuchholz » 2013-08-30 20:34

Try the acties_before_insert function rather than the acties_after_insert.

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-08-31 11:01

Hi albuchholz,
Thanks for the advise. However same result.

Code: Select all

	function acties_before_insert(&$data, $memberInfo, &$args){
// Bij een nieuw record mutator = creator.
	$data['Mutator'] = $memberinfo['MemberId'];
		return TRUE;
Any more suggestions?

Ron

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Set a Mutator field at Insert

Post by KSan » 2013-08-31 16:20

Have you tried

$data['Mutator'] = $dataa['Creator'];

In after_insert?

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-09-01 13:19

Hi Ksan,
I've just tried your "solution" however, no results.
Any other suggestions, I guess it should be something simple

Ron

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-09-25 14:46

Hi There,
Is there someone who can help me out please?

Ron

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Set a Mutator field at Insert

Post by AhmedBR » 2013-09-25 16:12

I am not much of a PHP coder but try this tip, what you need should be something very similar:

http://forums.appgini.com/phpbb/viewtopic.php?f=4&t=786
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-09-26 10:07

Hello AhmedBR,
Thank you for the "hint". I've tried the proposed solution and "altered" it to my case, however.... No result.
I might do something wrong. Maybe someone in the forum can tell what I do wrong.

Used Alteration: Tablename: Acties, used fieldnames: mutator and creator

Case:
When a new record has been made I like to have filled the mutator_field with value of the creator_field

Code: Select all

function acties_after_insert($data, $memberInfo, &$args){
	// Bij een nieuw record mutator = creator.
	sql("update `acties` set `mutator`= 'CUS{$data['creator']}' where `creator` = LAST_INSERT_ID()", $eo);
		return TRUE;
Attachments
Appgini.JPG
Defintion table Acties within AppGini
Appgini.JPG (147.5 KiB) Viewed 9573 times
No Mutatorvalue.JPG
No Mutator value after create a new record
No Mutatorvalue.JPG (39.05 KiB) Viewed 9573 times
Definition.JPG
SQL-Definition table Acties
Definition.JPG (38.43 KiB) Viewed 9573 times

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Set a Mutator field at Insert

Post by AhmedBR » 2013-09-26 11:36

I can see some problems in your code, the correct one is below (all names are case sensitive, at least on my server, and another error):

Code: Select all

function acties_after_insert($data, $memberInfo, &$args){
   // Bij een nieuw record mutator = creator.
   sql("update `acties` set `Mutator`= '{$data['Creator']}' where `Id` = LAST_INSERT_ID()", $eo);
      return TRUE;
Give it a try
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-09-26 13:23

He AhmedBR,
This did the trick!!.
Thak you so much. It is great to have a forum
2 alterations:
1. Case sensitive
2. Leaf CUS

But what does 'CUS{$data['creator']}' mean
instead of what it is now:
'{$data['Creator']}'

Ron

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Set a Mutator field at Insert

Post by AhmedBR » 2013-09-26 14:10

I totally agree, it is really GREAT.
CUS was just an abbreviation from CUSTOMER (three letters from it) to be added to the ID field since auto_increment only accepts Integers.
Instead of having Customer ID as: 0001 for example
With CUS I get it as CUS0001, which makes more sense to my users than 0001
For supplier I would us SUP0001
This way you would be able to tell which is which easily.

'CUS{$data['creator']} The result will be: CUS+what ever you have in creator
'{$data['Creator']}' The result will be: ONLY what you have in creator, which you need.
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Set a Mutator field at Insert

Post by RonP » 2013-09-26 14:22

Oké.
It is clear to me.I'll post a new "problem" :D

Ron

Post Reply