Additional comments and attachments are not being copied.

Community Alums
Not applicable
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);
9 REPLIES 9

Sohithanjan G
Kilo Sage
Kilo Sage

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);

 

🙂

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Community Alums
Not applicable

not working

 

@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....

LinkedIn - Lets Connect

Sandeep Rajput
Tera Patron
Tera Patron

@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