Need help generating a PDF and attaching to a record.

Jeffrey Siegel
Mega Sage

I have a custom table u_pco.  I created a widget and a service portal page to display the contents of the record in a letter format.  I currently have a UI action thats working nicely to display and send the print command for the url.  however, i have a need to have a button to generate a PDF of the page and attach it to the record, so that it can be sent out via an email notification.  

Does anyone know how i can adjust this print client script to generate a pdf of the service portal page and attach it to my current record without user intervention (except clicking of the button to trigger)

 

my UI Action script:

function PrintPCOLetter(){
if(g_form.modified){
		alert("Please save the form before continuing");
		return false;
	}
	var url = 'sp?id=pc_letter&sys_id='+g_form.getUniqueValue()+"&print=false";
	window.open(url, "_self");
	//g_navigation.openPopup(url);
	return false;
}

about this simple script: the script, ensures that the form isnt "dirty before allowing to proceed"

then sets the URL to goto the service portal page "pc_letter" and grabs the sys id and print parameter that the widget is using to a) get the desired record, and the print=false advises to show the letter, not print it using system dialog once loaded. (if print=true then the system dialog will automatically send the page to the system print dialog, allowing the user to choose which printer and see a preview)

 

 

9 REPLIES 9

Periyasamy P
Tera Guru

You can use below PDF utils to create pdf file and attach it to record.

 

PDFGenerationAPI()

Cell()

Documents()

i saw that option, but its looking for an html string, i have a whole html page, with CSS to style it, that i cant figure out how to use that as the page to create a pdf from.  any help would be appreciated.

Yes, you can pass everything as string. Refer below script and file generate from this script.

var html = "<html><head><style>body {background-color: lightblue;h1 {color: white;text-align: center;}p {font-family: verdana;font-size: 20px;}</style></head><body><h1>My First CSS Example</h1><p>This is a paragraph.</p></body></html>";

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

var hfInfo = new Object();


var result = v.convertToPDFWithHeaderFooter(html, "incident", "7b5a0cdf2fc1c110c767bac62799b60b", "myPDF", hfInfo);
gs.info(JSON.stringify(result));

can i pass variables from my record into this script?  i have to show this html page AND have a pdf option, id like to not have to keep two html codes in synch when changes are requested to the document.  if i can point to my service portal page to get the content, that would be more ideal.