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

Hi Sami,



In the UI macro, I was more thinking about reusing and adapt to an UI action the code here (if you want to have something into the form):


var mExport = new GwtContextMenu('context_pdfsub${jvar_section_id}');


mExport.setTableName('${ref}');


mExport.clear();


mExport.addFunc("${gs.getMessage('PDF (Portrait)')}", function() { exportToPDF('${ref}','$[${ref}.sys_id]',false,'${JS:sysparm_view}'); });


mExport.addFunc("${gs.getMessage('PDF (Landscape)')}", function() { exportToPDF('${ref}','$[${ref}.sys_id]',true,'${JS:sysparm_view}'); });


more specifically the function part



Same thing with the UI Context menu (if you want to have a specific list export):


/**


* Script executed on the Client for this menu action


*


* The following variables are available to the script:


*       'g_list' the GlideList2 that the script is running against (only valid for List context menus)


*       'g_fieldName' the name of the field that the context menu is running against (only valid for List context menus)


*       'g_sysId' the sys_id of the row or form that the script is running against


*       'rowSysId' is also set to the sys_id of the row to support legacy actions, but g_sysId is preferred


*/


runContextAction();



function runContextAction() {


   


    var sysparm_rows = g_list.grandTotalRows;


    var num_rows = parseInt(sysparm_rows);


    var sysparm_query = g_list.getQuery({all: true});


   


    var sysparm_view = g_list.view;


    if (num_rows < g_export_warn_threshold) {


          var dialog = new GwtPollDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');


          dialog.execute();


          return;


    }


    var dialog = new GwtExportScheduleDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf');


    dialog.execute();


}



But in all cases, don't forget to document because the features aren't documented and might be obsolete one day.



Regards,


Lam_Hoang
Kilo Expert

Custom PDF Files in ServiceNow through PDFCrowd-John James Andersen



you can take a look here to create some pdf files from ServiceNow.


Loudigi
Kilo Sage

JonathanJacob
Mega Sage

Have you looked at this Wiki Article PDF Web Service - ServiceNow Wiki?



Here is a quick UI action I created:


Client: True


OnClick: createPDFESS()


function createPDFESS() {


  var sysparm_table = g_form.getTableName();


  var sysparm_sys_id = g_form.getUniqueValue().toString();


  var url = sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id;


  window.open(url);


}


How would I force the report to open in Landscape instead of Portrait?



Thanks.