Business Rule on sys_audit Table - Performance Issue?

Shawn Dowler
Tera Guru

To be able to report on how many users are getting things assigned to them (and to help find users who are not utilizing their ServiceNow licenses) I created a table with Reference fields to sys_db_object and sys_user and a Document ID field to store the record. I have a couple of options. To populate the table initially, I wrote a script like the following:

(function() {

  var grAudit = new GlideRecord('sys_audit');

  grAudit.addEncodedQuery('fieldname=assigned_to^sys_created_on>javascript:gs.daysAgoStart(1000)');

  grAudit.query();

  while (grAudit.next()) {

      var grHistory = new GlideRecord('u_assigned_to_history');

      grHistory.initialize();

      grHistory.u_assigned_to = grAudit.newvalue;

      grHistory.u_task = grAudit.documentkey;

      grHistory.u_audit_timestamp = grAudit.sys_created_on;

      grHistory.u_table = grAudit.tablename;

      grHistory.insert();

  }

})();

Going forward I could modify this script to only query for records from yesterday for example and schedule it to run nightly or I could create a business rule on the sys_audit table to create these records any time a record is inserted into the sys_audit table matching the query criteria.

My question: should I be worried about adding a business rule to the sys_audit table? With the number of records added all the time, would this significantly, negatively impact performance on my instance? It's difficult to load test something like this. If it's not bad for performance, then I'd much rather do it with a business rule. That way the data is always up to date and I reduce the probability of duplicate records in my reporting table.

1 ACCEPTED SOLUTION

Yes. Exactly. I had tried few days back and it didn't seem to work..


View solution in original post

9 REPLIES 9

You can raise a support ticket and check if you need to go anytime for the business rule. There might be some property for making the business rule run  


Kalaiarasan Pus
Giga Sage

Pradeep Sharma Any idea why the business rule doesn't run on insert on audit table? Any property to enable this?


Hi Kalai,



You have to check update checkbox to true in BR. However I would recommend to go with schedule jobs and run during the non business hours.



Please let me know if you have any questions.


Yes. Update is working but insert is not. Any way to enable this ? Any property that you are aware of ? I know that it is not recommended but just want to check with you if it's possible..


I have not tried this scenarios. However as far as I know there is no property as such.