Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Excluding tables from system clone

adrianblakey
Tera Contributor

Hi - we've been asked to exclude all our HR module data (hr cases, tasks, attachments etc) from our sytem clones

I understand from the documentation that you cannot exclude a table inherited from the task table.

https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/administer/managing-data/task/t...

THe queston is whether anyone has found a way to only partially exclude data from the task table (i.e. where task type is HR task or HR case)?

I've just spent the whole day running a background script to delete the data after the clone, and I think this will become more of a time issue hte more data is intered ito our system.

Also, I added a simple exclude on the sys_attchments table which doesn't seem to have worked either..

Has anybody encountered or overcome anything like this?

1 ACCEPTED SOLUTION

Use the GlideTableCleaner API. It is optimized for speed and performance. For example, here's a piece of code that would delete any incident record created more than 1 second ago. The API also automatically detects and deletes related attachment records.


new GlideTableCleaner('incident', 1, 'sys_created_on').clean();



NOTE: Since this API is not documented it is not officially supported. Beware.


View solution in original post

10 REPLIES 10

HI - no way to exclude form the clone, I think this is because you cannot exclude tables that are inherited from the Task table. I've been running a post-clone script to remove cases , tasks, any remaining attachments and metrics.

 

 

// clean out HR case and HR task tables
new GlideTableCleaner('hr_case', 1, 'sys_created_on').clean();
new GlideTableCleaner('hr_task', 1, 'sys_created_on').clean();


// delete any remaining attachments
  var gratt = new GlideRecord("sys_attachment");
  gratt.addQuery('table_name', 'IN', 'hr_case, hr_task');
  gratt.query();
  gratt.deleteMultiple();

// delete any metrics for HR cases or HR tasks
  var grmtr = new GlideRecord("metric_instance");
  grmtr.addEncodedQuery('definition.table=hr_case^ORdefinition.table=hr_task');
  grmtr.query();