
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 07:39 AM
There are 240 incidents that we need to PDF and send do someone. Instead of doing it one by one as we need the export to be of the form is there a way to export each incident as a PDF via a script?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 01:51 PM
I think I figured out something in ServiceNow so that it create the PDFs and attaches them to record I created in another table as we do not want them attached to the incident record. I'm also able to set the name so it is not just incident.pdf. Here is what I did.
1. Created a custom table with only 1 string value called number. (this will get the number from the incident table).
2. Created 2 system properties with the admin user name and password.
3. Created a scheduled that is set to is run on demand with the following code.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('query string');
gr.query();
while (gr.next()){
var incPDF = new GlideRecord ('u_incident_to_pdf');
incPDF.initialize();
incPDF.u_number = gr.number;
var sysID = incPDF.insert();
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty('glide.servlet.uri') + 'incident'+ '.do?PDF&sys_id=' + gr.sys_id;
rm.setEndpoint(url);
// Create new properties and save user id and password of an admin account
rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
rm.saveResponseBodyAsAttachment('u_incident_to_pdf',sysID,gr.number+'.pdf');
var response = rm.execute();
}
Someone still has to go in and manually download each PDF but at least they do not have to rename them and then once they are done there is just a little clean up of deleting that attachment and the record in the table so it can be reused at a latter date and we are not clogging up ServiceNow with the no longer needed attachments.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 11:26 AM
Hello,
for doing this you need some programming skills, but here you have the way:
Call URL export programmatically
Un saludo,
Pablo Espinar
Consultant at Econocom Spain
Please mark this response correct if I've answered your question. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 11:57 AM
Thanks I will have to see if anybody in the company knows c#.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 01:51 PM
I think I figured out something in ServiceNow so that it create the PDFs and attaches them to record I created in another table as we do not want them attached to the incident record. I'm also able to set the name so it is not just incident.pdf. Here is what I did.
1. Created a custom table with only 1 string value called number. (this will get the number from the incident table).
2. Created 2 system properties with the admin user name and password.
3. Created a scheduled that is set to is run on demand with the following code.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('query string');
gr.query();
while (gr.next()){
var incPDF = new GlideRecord ('u_incident_to_pdf');
incPDF.initialize();
incPDF.u_number = gr.number;
var sysID = incPDF.insert();
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty('glide.servlet.uri') + 'incident'+ '.do?PDF&sys_id=' + gr.sys_id;
rm.setEndpoint(url);
// Create new properties and save user id and password of an admin account
rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
rm.saveResponseBodyAsAttachment('u_incident_to_pdf',sysID,gr.number+'.pdf');
var response = rm.execute();
}
Someone still has to go in and manually download each PDF but at least they do not have to rename them and then once they are done there is just a little clean up of deleting that attachment and the record in the table so it can be reused at a latter date and we are not clogging up ServiceNow with the no longer needed attachments.