Additional comments and attachments are not being copied.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2024 11:26 PM
var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
//change.cmdb_ci = current.cmdb_ci;
//change.priority = current.priority;
change.comments = current.comments.getJournalEntry(-1);
change.requested_by = current.caller_id;
//var c = current.comments.getJournalEntry(-1);
//change.comments.setJournalEntry(c);
var sysID = change.insert();
//current.rfc = sysID;
//var mySysID = current.update();
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('incident', current.sysID, 'change_request', sysID);
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 12:06 AM
Hi @Community Alums
You can use this script. I did some changes & its working fine for me. Let me know if you need anything more.
var change = new GlideRecord("change_request");
change.initialize();
change.short_description = current.short_description;
change.description = current.description;
change.requested_by = current.caller_id;
// Copy comments
change.comments = current.comments.getJournalEntry(-1);
var sysID = change.insert();
// Copy attachments
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('incident', current.sys_id, 'change_request', sysID);
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 12:58 AM
not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 07:19 AM
@Community Alums,
The script given here by @Sohithanjan G must work, (correct code logic) do your needful to help the code adjustment to make it work on your instance.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 12:11 AM
@Community Alums Here is the updated code.
var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
//change.cmdb_ci = current.cmdb_ci;
//change.priority = current.priority;
change.comments = current.comments.getJournalEntry(-1);
change.requested_by = current.caller_id;
//var c = current.comments.getJournalEntry(-1);
//change.comments.setJournalEntry(c);
var sysID = change.insert();
//current.rfc = sysID;
//var mySysID = current.update();
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('incident', current.sys_id, 'change_request', sysID);
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
Regarding getJournalEntry(-1) returns all journal entries ever entered as a single string with each entry delimited by "\n\n". Hence you might be getting one single comment out of multiple comments from the incident record.
For more information please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/c_GlideElementAPI#r_GlideElement-getJournalEntry_Number?navFilter=getJou