Welcome! Log In Create A New Profile

Advanced

HDescribeTrigger

Posted by Joris 
Joris
HDescribeTrigger
September 23, 2008 10:33AM
Hi,

I'm having this situation :

Our customer wants to know for every file who has created a record an when, and who has made the last modification to a record and when. So I added these fields to every file in the project : USRCREATION, DATECREATION,USRMOD,DATEMOD

I have decided to create a trigger to apply these values to the file. Therefore i have created 2 triggers like this :
HDescribeTrigger("*","HMODIFY","TRIG_Modify",hTriggerBefore)
HDescribeTrigger("*","HADD","TRIG_Add",hTriggerBefore)

So i don't have to worry about these fields anymore, they must be automatically filled by these triggers in the procedures TRIG_Modify and TRIG_Add

This is what i tried in the TRIG_modify procedure :
PROCEDURE TRIG_Modify()

usrcreation = gpwGetUserInfo(gpwInfoLogin)
datecreation = Today


Now here is my problem :
How do i know the name of the current file? I can not apply a value to a field without knowing the file it belongs to. And i don't want to create a seperate trigger and procedure for each of my files.

Any ideas? Maybe with indirection? Thanks for helping.

Joris
Marius
Re: HDescribeTrigger
September 23, 2008 11:25AM
Hi Joris

Have you considered using the build in "LogMethod". (Various Tab in the File Describtion window - Analysis) You don't have to write code and what you need is probably there.

Regards
Marius
Paulo Oliveira
Re: HDescribeTrigger
September 23, 2008 11:42AM
just look in the help for triggers.
you have several predefined variables:
H.FileName
Character string: Logical name of the file for which the trigger is activated.

H.Action
Character initialized to "A" for a trigger Before, and "P" for a trigger After.

H.TriggerFunction
Character string: Name of the Hyper File function that started the trigger.

H.ToDo
During the execution of a before trigger, you can cancel the execution of the current Hyper File function by assigning "A" to the Hyper File state variable: h.todo = "A"

In your case use the H.FileName

PS: If you use sql INSERT/UPDATE the triggers don't work, they only work with HADD/HMODIFY. If you use sql (SQLSERVER, ORACLE) the triggers must be managed in the DB and not in the windev code.
Peter Holemans
Re: HDescribeTrigger
September 23, 2008 11:46AM
Easy... Here's an example:
PROCEDURE TRG_SetAuditTrail()
//Start trigger logic
SWITCH Upper(H.Action)
	CASE "A"  // Trigger before
		//Check the called function
		SWITCH Upper(H.TriggerFunction)
			CASE "HADD", "HAJOUTE"
				{H.FileName+".CreatedBy ",indItem}=objSession::str_SessionUserName
				{H.FileName+".CreatedOn",indItem}=DateSys()+TimeSys()
				{H.FileName+".LastUpdatedBy",indItem}=objSession::str_SessionUserName
				{H.FileName+".LastUpdatedOn",indItem}=DateSys()+TimeSys()
			CASE "HMODIFY", "HMODIFIE"
				{H.FileName+".LastUpdatedBy",indItem}=objSession::str_SessionUserName
				{H.FileName+".LastUpdatedOn",indItem}=DateSys()+TimeSys()
			CASE "HCROSS", "HRAYE"
				{H.FileName+".LastUpdatedBy",indItem}=objSession::str_SessionUserName
				{H.FileName+".LastUpdatedOn",indItem}=DateSys()+TimeSys()
		END
		
	CASE "P"  // Trigger After
END
Joris
Re: HDescribeTrigger
September 23, 2008 02:48PM
OK, thanks a lot for the info. :cheers:

I should have known about the H.Filename command, but i've never used it before.

(The logging system is not an option, the user name and date should be visible in my application.)

Joris.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: