I want to email the incident record form as a PDF file

bonsai
Mega Sage

I want to use the business rules for the incident record creation trigger to save the contents of the incident record form as a PDF file in another table.

I thought I could use the context menu function to export to PDF file, but it was downloaded as a local file, so I couldn't use it.

I also tried to come up with the following script using the following article as a reference,
but it doesn't work well.

 

 

https://www.servicenow.com/community/developer-forum/export-of-incidents-to-pdf/m-p/2252171#M903275

 

 

try {
var gr = new GlideRecord('incident');
gr.addEncodedQuery('state=7');
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 = 'https://XXXX.service-now.com/now/nav/ui/classic/params/target/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("user_id", "user_PW");
        rm.saveResponseBodyAsAttachment('u_incident_to_pdf', sysID, gr.number + '.pdf');
        var response = rm.execute();
		gs.info(gr.number+"_"+response.getStatusCode());

    }
} catch (ex) {
    var message = ex.getMessage();
    gs.info(message);
}

 

A record will be created in a separate table, but no attachment will be created.

The requirement is that when creating an incident record, a record will be created in a separate table with the incident contents attached as a PDF file.
The PDF content will be the same as the PDF export in the context menu.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

you can do this approach

1) have after insert BR on incident table and create and add that pdf as attachment on incident record

2) then trigger notification and ensure Include attachment checkbox is checked

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

This script does not create attachments.

I would like to convert the records to PDF, but am I using the script incorrectly?