Clone cleanup script not running

Rolf Nyhus
Tera Guru

To avoid moving a large number of Incidents from our Prod to Test environment during cloning, I tried to use a Clone Cleanup Script, however it never ran.

I verified that the script was good in Test, because since it never ran post-cloning, I had to manually run it in Test.

According to the ServiceNow doc, the cleanup scripts should run automatically after cloning is done.:
https://docs.servicenow.com/bundle/london-platform-administration/page/administer/managing-data/concept/post-clone-cleanup-scripts.html

Does anyone know if there are any properties that need to be set in order to activate the cleanup scripts or know any other reason for it not running?

Yes, I did add the cleanup script on Prod (System Clone => Cleanup Scripts), and we only have one clone target defined, which is Test.

 

Here is the script:

//Script to delete all incidents older than cut off date
//To change cut off date, adjust the number of days defined in daysOffset

var daysOffset=90;
var cutOffDate = gs.daysAgo(daysOffset);
var deleteCount=0;

gs.log("STARTING DELETING INCIDENT RECORDS");
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on','<', cutOffDate);
gr.query();
while(gr.next()){
 gr.deleteRecord();
 deleteCount++;
}
gs.log("FINISHED DELETING " + deleteCount + " INCIDENT RECORDS AS THEY WERE MORE THAN " + daysOffset + " DAYS OLD.");

5 REPLIES 5

Hi Uday,

The "solution" provided by the KB doesn't really resolve the root cause, instead it offers an alternative method to manually running the cleanup script. However, since this method also requires a script, it seems just as easy to manually run the cleanup script. Still it's good to know about. Thanks for your follow-up on this topic!