Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..
1000 views

Audit on deleting a record

Jump to solution

I am auditing security group field on operator table

This is what i have done so far

Turned Audit On
Created auditspec entry
Created 3 triggers
2 - After Add, 4 - After Update, 5 - Before Delete, with the application as "trigger.invoke.auditor"

Audit record is generated when a new operator record is created, when an operator record is modified, but not when an operator record is deleted. I would like to audit the security group field when an operator record is deleted.

Tags (3)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Audit on deleting a record

Jump to solution

Yeah, I ran into that same issue as well.  It's almost as though the 'trigger.invoke.auditor'  loses track of the new record after the record deletes, so it fails to do a compare between the contents in the old record and the contents of the new.

So, I came up with the following workaround - 

I set up a trigger record like:

Trigger Type: 5 - Before Delete

Script -

var fFile = new SCFile(system.functions.filename(record))
fFile.logical_name = record.logical_name
audit(oldrecord,fFile)

function audit(oldFile,fFile){
var argNames = new SCDatum();
var argVals = new SCDatum();
var retCode
argNames.push("file")
argNames.push("second.file")
argVals.push(oldFile)
argVals.push(fFile)

system.functions.rtecall("callrad", retCode, "audit.compare", argNames, argVals, false)
}

 

What that does is it acually calls the audit.compare RAD from inside a trigger record, calling an initialized version of a blank record, and comparing that to the pre-deleted version of the record, and that seems to work.

View solution in original post

13 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Audit on deleting a record

Jump to solution

Hi,

Did you try the "after delete" action already? If not, please let me know the result.

Regardsm,

If you feel this was helpful please click the KUDOS! thumb below!
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Audit on deleting a record

Jump to solution

Yes,  I tried that and it doesn't work

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Audit on deleting a record

Jump to solution

Hi,

Could you give me the details about the SM version you have. RTE and APP?

Regards,

If you feel this was helpful please click the KUDOS! thumb below!
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Audit on deleting a record

Jump to solution

Application Version: 9.31.0022

RTE Version: 9.31.3051

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Audit on deleting a record

Jump to solution

Hi,

Please place this code into the trigger:

var rcode = new SCDatum;
system.functions.rtecall("log", rcode, "<HPSupport> Trigger has been called. Operator: "+system.functions.operator() + " Time: " + system.functions.tod());

Let's replicate the issue reported and chcek if into the sm.log there is an entry like this one: <HPSupport> Trigger has been called. Operator:. 

Regards,

If you feel this was helpful please click the KUDOS! thumb below!
0 Likes
Highlighted
Established Member..
Established Member..

Re: Audit on deleting a record

Jump to solution

I don't think it's a easier to check whether the trigger is executed or not.  You know too many triggers will be executed. 

 

Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Audit on deleting a record

Jump to solution

Yeah, I ran into that same issue as well.  It's almost as though the 'trigger.invoke.auditor'  loses track of the new record after the record deletes, so it fails to do a compare between the contents in the old record and the contents of the new.

So, I came up with the following workaround - 

I set up a trigger record like:

Trigger Type: 5 - Before Delete

Script -

var fFile = new SCFile(system.functions.filename(record))
fFile.logical_name = record.logical_name
audit(oldrecord,fFile)

function audit(oldFile,fFile){
var argNames = new SCDatum();
var argVals = new SCDatum();
var retCode
argNames.push("file")
argNames.push("second.file")
argVals.push(oldFile)
argVals.push(fFile)

system.functions.rtecall("callrad", retCode, "audit.compare", argNames, argVals, false)
}

 

What that does is it acually calls the audit.compare RAD from inside a trigger record, calling an initialized version of a blank record, and comparing that to the pre-deleted version of the record, and that seems to work.

View solution in original post

Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Audit on deleting a record

Jump to solution

I have tried this and it is working

5 - Before Delete

r = record;
var today= new Date();
var auditRec = new SCFile( "audit" );
auditRec.filename = "operator";
auditRec.unique_a = r.name;
auditRec.operator = system.functions.operator();
auditRec.recorded_date_time = today;
auditRec.mod_fields[0]="security.group";
auditRec.recorded_changes[0].fieldname="Security Group";
auditRec.recorded_changes[0].old_array=r.security_group;
var rc = auditRec.doInsert();

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Audit on deleting a record

Jump to solution

That can work, but then your custom script has to specify the fields within the script, instead of using the auditspecs record to track which fields you want in the audit.

Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Audit on deleting a record

Jump to solution

Hi,

The print code should be place only in the delete trigger. However, please check the workaround posted it should work in your scenario as well.

Regards,

If you feel this was helpful please click the KUDOS! thumb below!
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Audit on deleting a record

Jump to solution

The only problem i see with the solution you have provided is it doesnt record the "Unique A" field when i delete the operator record.

"Unique A" field is the unique key on operator table which is the field "name" which is also mentioned in the "auditspec" table. This get recorded on Add and Update but not on Delete when i use your code.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.