Can I attach a PDF export of a record to that same record with PDFGenerationAPI?

Brad Cupp
Giga Contributor

Hello,

I am trying to use PDFGenerationAPI to create a PDF of a record(similar to export PDF functionality), and attach it to the same record. Based on the documentation the API only seems to have the option to create a PDF with HTML, not a url. Can this API do what I am looking for? If it can't, is there another way to solve this problem?

Thanks in advance!

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Hey Brad,

You can use code provided on the below link to fullfil your needs.

https://community.servicenow.com/community?id=community_question&sys_id=d03ee971db8f4410feb1a851ca96...

Regards,

Muhammad

Regards,
Muhammad

View solution in original post

2 REPLIES 2

MrMuhammad
Giga Sage

Hey Brad,

You can use code provided on the below link to fullfil your needs.

https://community.servicenow.com/community?id=community_question&sys_id=d03ee971db8f4410feb1a851ca96...

Regards,

Muhammad

Regards,
Muhammad

MrMuhammad
Giga Sage

You can also try this in the UI action which I'm using already. Change Username and Password in the below script before execution.

UI ACTION SCRIPT:

createPDF();

function createPDF() {
	
    var rm = new sn_ws.RESTMessageV2();
    rm.setHttpMethod('GET');
	
    var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
    
	gs.addInfoMessage(url);
    
	rm.setEndpoint(url);
    // Create new properties and save user id and password of an admin account
    rm.setBasicAuth('USERNAME', 'PASSWORD'); // Replace USERNAME and PASSWORD with actual username and password.
    rm.saveResponseBodyAsAttachment(current.getTableName(), current.sys_id, current.number + ".pdf");
    var response = rm.execute();
    action.setRedirectURL(current.getTableName() + ".do?sys_id=" + current.sys_id);

}

 

Regards,
Muhammad