Report attachment to the Incident table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 06:31 PM
Hi Team,
system has a create a incident on daily basis , along with report which need to attach to it the newly created incident .
senario: In the user table , i need to query locked out is true and source is empty , if there is list of users greater than 0 it has to create the Incident (I have wrote the schedule script execution job which is working fine).
But it has to attach the list of users to the incident when creating the record or in the short descriptions i has to provide the list of users.
Guide me how to implement this thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 10:10 PM
Hello Megana,
Attaching the report may be complex one. but showing user details in description would be easy.
try below script to include user details in description.
var desc = "Locked out users are as follows:\n";
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery("locked_out=true^sourceISEMPTY"); // verify field names
gr.query();
while(gr.next()){
desc = desc+"User Name: "+gr.name+"\t\t"+"User ID: "+gr.user_name+"\n";
}
now copy desc variable value in incident description field (not short description).
let me know for any issue.
Thanks,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 11:33 PM
Hi Megana,
You can try using GlideSysAttachment.write method for getting an excel created & getting it attached. I did the same for getting variables submitted exported to an excel as a list & got it attached to the RITM created.
You may find links helpful.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2020 06:02 AM
I had a similar requirement with the client.
I had to generate report and attach that to a newly created record.
This is what i have done.
1) Create a report with necessary filters in View/Run.
2) Schedule a report with sharing of generated report in scheduled jobs and set an email id to sent to and scroll down to select the format of report to excel.
3)Use this script to attach the generated report in another scheduled report:
var gr3 = new GlideRecord("sys_attachment");
gr3.addEncodedQuery("file_name=destruction report.xls"); //this is report generated in second step.
gr3.orderByDesc('sys_created_on');
gr3.setLimit(1);
gr3.query();
var attachmentID = '';
var tableName = '';
var tableSysId = '';
if (gr3.next()) {
attachmentID = gr3.getUniqueValue();
tableName = gr3.table_name;
tableSysId = gr3.table_sys_id;
}
gs.log("attachment id is: "+ attachmentID);
var gr = new GlideRecord("u_travel_book_agency");
gr.initialize();
gr.u_user = "e69292c92fec20102b117f572799b691";
gr.u_mode_of_transport = "1";
gr.u_enter_coupon_code = "NEWUSER";
var lastInsertedID = gr.insert();
gs.log("last id: "+ lastInsertedID);
var a = GlideSysAttachment.copy(tableName,tableSysId,'u_travel_book_agency',lastInsertedID);
gs.log(" a: : "+ a);