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

Harsh Vardhan
Giga Patron

Thanks, Harshvardhan. I've read the post, but it doesn't really tackle my issue which is non-execution of the script. The post only talks about execution order.

I would suggest you open an HI ticket in parallel

Community Alums
Not applicable

Hi Rolf,

The below link will help you to execute the cleanup script in the target instance.

Note: Make sure you had imported the cleanup script from the source instance.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783212