Export to PDF UI Action

abhijats
Tera Expert

Hi Everyone,

Can you please tell me how to create a UI Action(Export to PDF) on ESS Portal for exporting the form(UI Page) in PDF Format, Actually we have to give functionality to user to extract the form from ESS Portal related to certain category and then use it in PDF Format.

27 REPLIES 27

Brian thanks for your really.Actually I have 17000 records which has columns of 3 tables with images.Can it support to fulfill my need ?  


Jonathan,


I am trying to do something a bit different but I think similar.


I am attempting to create a pdf of a record and attach it to itself.


The attach to itself part is working but the content of the pdf is all wrong.


I am doing this in a UI action, any pointers would be greatly appreciated!



--------------------


var attachment = new Attachment();


var attachmentRec = attachment.write('u_wacky_table', current.sys_id, (current.number), "application/pdf",'g_form.'+'u_wacky_table'+'.do?PDF&sys_id=' + current.sys_id);


gs.addInfoMessage(attachmentRec);


------------------------------



thank you


Brian


Brian,



When you say the content is all wrong do you mean the fields displayed are wrong or is the file damaged and not opening?


I don't think the content is acccepted.  The pdf fails.



Sent from Yahoo Mail on Android



On Tue, Sep 6, 2016 at 4:11 PM, jonathanjacob<community-no-reply@servicenow.com> wrote:


  • a body {font-family:Helvetica, Arial, sans-serif;} h1, h2, h3, h4, h5, h6, p, hr {}.button td {}


|







|


Export to PDF UI Action



reply from Jonathan Jacob in User Interface - View the full discussion



Brian,



 



When you say the content is all wrong do you mean the fields displayed are wrong or is the file damaged and not opening?



Reply to this message by replying to this email, or go to the message on ServiceNow Community


Start a new discussion in User Interface by email or at ServiceNow Community


Following Export to PDF UI Action in these streams: Inbox







.footerlinks


|


This email was sent by ServiceNow Community because you are a registered user. You may unsubscribe instantly from ServiceNow Community, or adjust email frequency in your email preferences



So the easiest way to do so is using a Rest Message via the UI action:



(also I see you are mixing client/server APIs... g_form is a client side API... Attachment, restMessage and gs. are server side APIs.) Make sure your UI action runs server side.



var rm = new sn_ws.RESTMessageV2();


rm.setHttpMethod('GET');


rm.setEndpoint(current.getTableName()+ '.do?PDF&sys_id=' + current.sys_id);


rm.saveResponseBodyAsAttachment(current.getTableName(),current.sys_id,fileName);


var response = rm.execute();


if(response.getStatusCode()==200) {


        // gs.addInfoMessage('Added attachment!');


}




See the following for more info:


https://developer.servicenow.com/app.do#!/api_doc?v=geneva&type=server&scoped=true&to=method_class__...