How to clone a service request (or an incident) and attach all the related data to that clone?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2016 12:40 PM
Just wonder if anyone has the answer for the following requirement/ask:
Goal:
Clone existing records (mostly service requests or incidents) along with all the related data attached to them, and then transfer the cloned records to another "non-ServiceNow" systems via web services.
Why do you need to clone existing records?
Due to limited time and resources, the other "non-ServiceNow" systems can only accept "new" records during creation.
Many thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 07:39 AM
You can do a UI Action or whatever to do the copy:
var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = current.caller_id;
inc.short_description = current.short_description;
[...] // all fields you want to copy should be in your script.
var newSysID = inc.insert();
GlideSysAttachment.copy('incident', current.sys_id, 'incident', newSysID);
That should copy all attachments to you new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 07:53 AM
Mike,
Thank you for your reply and this is close to what I am looking for for incident, what about request? Can you also "clone" it with all the related data (including related request items and catalog tasks)? In addition, can you export the original record as a pdf file and attach the pdf file to the cloned record (the purpose is to help capture all notes in the journal fields, and export the pdf file together with that cloned record via web services, or via email)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 08:43 AM
With that, you would have to do multiple GlideRecord inserts:
var req = new GlideRecord('sc_request');
req.initialize();
req.caller_id = current.caller_id;
req.short_description = current.short_description;
[...] // all fields you want to copy should be in your script.
var newSysID = req.insert();
var reqItem = new GlideRecord('sc_req_item');
reqItem.addQuery('request', current.sys_id);
reqItem.query();
while(reqItem.next()){
var newReqItem = new GlideRecord('sc_req_item');
newReqItem.initialize();
newReqItem.request = newSysID;
newReqItem.field = reqItem.field;
[...] // all fields you want to copy should be in your script.
newReqItem.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 08:44 AM
There is a way to call that GlideRecord('sc_req_item') piece only once, but I don't know it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 10:52 AM
Mike,
Have you tried the following "Export and attach" UI Action? Maybe this can be combined with your code to "Clone, Export, and Attach".
(Clicking the link above did not take me directly to the right page, so I had to copy and paste the url: share.servicenow.com/app.do#/detailV2/3aa3eee72bf5e1004a1e976be8da1590/overview)