Audit Records

Contains tips for configurators working with Aware IM
Craig
Posts: 85
Joined: Sun Apr 26, 2009 1:26 pm

Post by Craig »

I have 3 tables:
Customer: Fname,Lname
AuditLog: CreatedBy,Time,AuditLogId
CustomerLogs:Fname,Lname,AuditLogID(Type:AuditLog)


I have 2 rules for Customer: (when object is created or modified)

If Customer WAS CHANGED OR Customer IS NEW Then
CREATE Auditog WITH Auditog.time=CURRENT_TIMESTAMP,Auditog.CreatedBy=LoggedInSystemUser.LoginName,Auditog.AuditLogId=MAX Auditog.auditId+1
CREATE CustomerLogs WITH CustomerLogs.Fname=ThisCustomer.Fname,CustomerLogs.Lname=ThisCustomer.Lname,CustomerLogs.AuditLogId=CustomerLogs.AuditLogID.AuditLogId

My AuditLog table gets populated correctly. But the AuditLogID in the CustomerLogs table is empty.
What am i doing wrong? Please help as I am new to awareIM
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Looks like:

CustomerLogs.AuditLogId=CustomerLogs.AuditLogID.AuditLogId

Should be:

CustomerLogs.AuditLogId=Customer.Id


By the way, I don't think you should need the prefix "THIS" in from of the other parts of this rule.
Tom - V8.8 build 3137 - MySql / PostGres
Craig
Posts: 85
Joined: Sun Apr 26, 2009 1:26 pm

Post by Craig »

Tom,

Thanks for that. But, In the CustomerLogs table, i want the value for AuditLogID the same one which gets into the auditLog table.. is there some other way to do this?
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Are you trying to store the ID of the Auditlog in the CustomerLogs BO?

If so, I would try:

CREATE Auditlog WITH Auditlog.time=CURRENT_TIMESTAMP,Auditlog.CreatedBy=LoggedInSystemUser.LoginName

CREATE CustomerLogs WITH CustomerLogs.Fname=Customer.Fname,CustomerLogs.Lname=Customer.Lname,CustomerLogs.AuditLogId=CustomerLogs.AuditLog.id
Tom - V8.8 build 3137 - MySql / PostGres
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

Craig,

Since CustomerLogs.AuditLogID is Type:AuditLog

I think you can just do

CREATE CustomerLogs WITH
CustomerLogs.Fname=Customer.Fname,CustomerLogs.Lname=Customer.Lname,CustomerLogs.AuditLogId=AuditLog

Since AuditLog was just created, it should be in context.

Not sure it matters, but what is the relationship between ustomerLogs and AutidLog?
Bob
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Oops -- My second line should have been:

CREATE CustomerLogs WITH CustomerLogs.Fname=Customer.Fname,CustomerLogs.Lname=Customer.Lname,CustomerLogs.AuditLogId=CustomerLogs.id

CustomerLogs.id should be in context here since it was just created in the first rule.
Tom - V8.8 build 3137 - MySql / PostGres
Craig
Posts: 85
Joined: Sun Apr 26, 2009 1:26 pm

Post by Craig »

Tom,

Thanks for your replies...
i did the following and got it working:
Rule invoked when instance ofcustomer object is created:

If Customer IS NEW
Then
CREATE CustomerLogs WITH CustomerLogs.CustNo=ThisCustomer.CustNo,CustomerLogs.Fname=Customer.Fname,CustomerLogs.Lname=Customer.Lname
CREATE Auditog WITH Auditog.objectModified='Customer',Auditog.reference=ThisCustomer.Fname,Auditog.time=CURRENT_TIMESTAMP,Auditog.userId=LoggedInSystemUser.LoginName,Auditog.auditId=MAX Auditog.auditId+1,Auditog.action='new customer'


Rule when an instance of AuditLog is created:
If Auditog IS NEW Then
FIND CustomerLogs WHERE CustomerLogs.auditId IS UNDEFINED
CustomerLogs.auditId=Auditog.auditId
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Very useful improvement in build 1212 descibed at http://www.awareim.com/changelog/Readme1212.txt

Function: GET_CHANGES

Description: If an object was changed returns which attributes have been changed as well as old and new values

Parameters: Object name that has been changed

Example: IF MyObject WAS CHANGED THEN CREATE AuditRecord WITH AuditRecord.Description=GET_CHANGES(MyObject)
Tom - V8.8 build 3137 - MySql / PostGres
Post Reply