UI Action -Print to PDF

pramn
Tera Guru

Morning Team, 

 

W have a requirement to Create a UI action to PRINT To PDF, I have done something but not getting expected result .

Could you Please help me with it .

pramn_0-1696571492832.png

script is 

 function gen_pdf() {
 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;
rm.setEndpoint(url);
rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.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);
 }
 
Please help me to fix this .
Thanks in advance .
10 REPLIES 10

Hi @pramn 

Can you capture a screenshot about what you have done so I can see what's going on?

It's totally working fine from my end.

pramn_0-1696585932149.pngpramn_1-1696586041150.png

Please check the screen shot 

Hi @pramn 

We should put these line scripts into a function. Use the below one

function printPDF(){
	var uri = g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
	g_navigation.open(uri);
}

 

 

Cheers,

Tai Vu

Hi @Tai Vu,

 

Is there a way to give a title to the PDF?

Amit Gujarathi
Giga Sage
Giga Sage

HI @pramn ,
I trust you are doing great.
Please try below script for the same

function print_to_pdf() {
    var url = '/' + g_form.getTableName() + '.do?PDF&sysparm_record_target=' + g_form.getTableName() + '&sysparm_record_id=' + g_form.getUniqueValue();
    window.open(url, '_blank');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi