Page 1 of 1

Set a Mutator field at Insert

Posted: 2013-08-29 11:45
by RonP
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

Re: Set a Mutator field at Insert

Posted: 2013-08-30 20:34
by albuchholz
Try the acties_before_insert function rather than the acties_after_insert.

Re: Set a Mutator field at Insert

Posted: 2013-08-31 11:01
by RonP
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

Re: Set a Mutator field at Insert

Posted: 2013-08-31 16:20
by KSan
Have you tried

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

In after_insert?

Re: Set a Mutator field at Insert

Posted: 2013-09-01 13:19
by RonP
Hi Ksan,
I've just tried your "solution" however, no results.
Any other suggestions, I guess it should be something simple

Ron

Re: Set a Mutator field at Insert

Posted: 2013-09-25 14:46
by RonP
Hi There,
Is there someone who can help me out please?

Ron

Re: Set a Mutator field at Insert

Posted: 2013-09-25 16:12
by AhmedBR
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

Re: Set a Mutator field at Insert

Posted: 2013-09-26 10:07
by RonP
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;

Re: Set a Mutator field at Insert

Posted: 2013-09-26 11:36
by AhmedBR
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

Re: Set a Mutator field at Insert

Posted: 2013-09-26 13:23
by RonP
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

Re: Set a Mutator field at Insert

Posted: 2013-09-26 14:10
by AhmedBR
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.

Re: Set a Mutator field at Insert

Posted: 2013-09-26 14:22
by RonP
Oké.
It is clear to me.I'll post a new "problem" :D

Ron