Automate scheduling clone request

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 03:33 AM
We need to schedule a clone every month from our production instance to our QA instance in order to validate against current data. Instance Data Replication (IDR) is not providing us the desired outcome.
ServiceNow provides a possibility to schedule clones in a frequent way with the attribute "Clone frequency" on a clone request. As soon as your choosing a clone frequency you need to set a number of occurences. If you e.g. select "Monthly" you can only schedule this request for in total 2 months. This is a quite low value and therefore we need to request clones manually! every two months.
Is there a working solution so that we can schedule clones for every month until e.g. in 5 years?
I know that some developers already tried this with creating the clone_instance records by script but didn't seem to work (see https://www.servicenow.com/community/developer-forum/is-it-possible-to-schedule-periodic-clones/m-p/...).
In order to probably get a OOB solution I'm going to create an Idea as well.
- Labels:
-
compliance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 03:50 AM
Hi @Marco Moro ,
To start with , I would assume this is possible, but I could see this going pretty badly.
If your plan is something like wanting to clone once a month, you might just consider a scheduling a notification to go out once a month to your admin reminding them to schedule a clone. You could even have a catalog item that gets generated that does some approvals then sends a task to set the clone. It's so easy to manually schedule a clone and I would think you do it infrequently enough that it may not benefit that much from being automated.
However if you are looking for it anyway then :
First goto Clone Targets under System Clone and create a target for this instance you wish to clone weekly (give the instance url, an admin id and password). Once that is done, goto scheduled job -> run a script of your choosing->Schedule it to run weekly on mondays at 01:00 or so, add the below code:- (Running it on a Monday adds a cone request for weekend so that you have a week to decide if you want to cancel the clone,just in case)
var gr=new GlideRecord("clone_instance");
gr.initialize();
gr.target_instance="<sys_id of your target instance record which you created in first step>";
gr.scheduled=gs.daysAgo(-5); //so that it runs on weekend
gr.email="<your email address>";
gr.insert();
Once the code executes, just type clone_instance.list in the left nav and see if the clone request got added.