- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2019 01:51 AM
Hi All,
would really appreciate you help.
I have created a UI Action which will create an "incident" from another table.
I want to copy all attachments over and have found some script which should allow me to do it but it does not seem to be working.
the script i copied from servicenow is below
GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id');
after my changes it appears like the below
GlideSysAttachment.copy('incident','8dce5f603733310099322b2943990e3c','u_incident_rt','0f425d0e37cdb2003332261953990e05');
When applying it to the UI Action, it looks like the below.
//create internal it incident and assign to group "All-staff"
var irt = new GlideRecord("u_incident_rt");
irt.short_description = current.short_description;
irt.description = current.number + '\n' + '\n' + current.description;
irt.priority = current.priority;
irt.work_notes = current.work_notes;
irt.u_caller_id = current.caller_id;
irt.company = current.company;
irt.setValue ('assignment_group', 'b3808e9337120200021e5ca543990e99');
irt.work_notes = current.work_notes.getJournalEntry(-1);
irt.comments = current.comments.getJournalEntry(-1);
GlideSysAttachment.copy('incident','8dce5f603733310099322b2943990e3c','u_incident_rt','0f425d0e37cdb2003332261953990e05');
var sysID = irt.insert();
I look forward to receiving some guidance and thanks in advance
Kind regards
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2019 05:23 AM
Hi Vikas,
Try below line in your code after var sysID = irt.insert();
GlideSysAttachment.copy('incident', current.sys_id, 'u_incident_rt', sysID);
var mySysID = current.update();
gs.addInfoMessage("Incident created");
action.setRedirectURL(incident);
action.setReturnURL(current);
// If you are copying attachment from the record in u_incident_rt table then the source table should be u_incident_rt . It should look //like below line
var gr = new GlideRecord("incident");
gr.short_description = "Demo";
// Set other field values
var sysID = gr.insert();
GlideSysAttachment.copy('u_incident_rt', current.sys_id, 'incident', sysID);
var mySysID = current.update();
gs.addInfoMessage("Incident " + gr.number + " created for this u_incident_rt");
action.setRedirectURL(incident);
action.setReturnURL(current);
Mark If Correct/Helpful.
Regards,
Ajay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 01:48 AM
Thanks Ajay, that has worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 04:37 AM
You're welcome...