Custom Audit table

shams
Kilo Contributor

Hi all!

 

Basically we have unaudited cmdb_ci extended tables . I would like to have a report on all changed fields (status, etc) in CI which have specific support group assigned.

 

I have created a table u_ci_audit, which i will use to create report based on. it contains pretty same fields as history table (field name, old value, new value, CI name)

 

Created business rule to trigger   when cmdb_ci record updated, inserted, deleted and it creates new record in audit table.

 

What is tricky is to create a script to create separate record in u_ci_audit table   for each changed field in CI.

I don't want to track all fields with function .changes() separately.

 

Any ideas will be appreciated

1 ACCEPTED SOLUTION

Bhavesh Jain1
Giga Guru

You can get all the fields of the form and apply changes() in a loop.


Below code is just an example of how you can refer to name/value of each field of a form.


var fields = current.getFields();


for (var i = 0; i < fields.size(); i++) {


  var field = fields.get(i);


  var name = field.getName();


  var value = field.getDisplayValue();


  gs.print(i + ". " + name + "=" + value);


}


View solution in original post

8 REPLIES 8

hi @Bhavesh Jain1 

 

here var fields = current.getFields(); getting all fields now I don't want all fields only selected fields I want to get for that I maintain one interface.

 

tablename  auditfield1    auditfield2    auditfield 3

incident       caller              state             Short Description

 

In that i mentioned table name and fields like as above now i need to check if values inserted/ updated i need to get field label, old value,new value of incident table in my custom audit table. 

 

 

 

Slava Savitsky
Giga Sage

Why not enable audit for these tables? Is your custom solution going to have some extra capabilities that are not available with the standard audit feature?


Hi!



The main idea is to build   and schedule report on changed fields of the supported CI in a scope for a given period.


It is not possible to do with the built-in audit table.


Philippe Casidy
Tera Guru

Hello,

 

I think you should look at Metrics (and metrics definitions) in ServiceNow. You should be able to track when/how long which field had some values.

 

Philippe