I want to generate a pdf of selected records in a list?

trinadhgottipat
Kilo Expert

Hi All,

I want to generate a PDF of selected records in a list, when the user clicks on 'Generate PDF' UI action(List Choice),created by me.

Is there a way I could do this.

Thanks,

Trinadh.Developer Community Service ManagementdvpChuck Tomasi's BlogPradeep Sharma's Blog ctomasi

1 ACCEPTED SOLUTION

Hi Trinadh,



Have a List UI Action either List bottom button or List context menu as per your need.


Select the checkbox for client and add this function downloadPdf()


In the script section add the following code. What it does is it gets the pdf for only those records which are selected in the list layout.


I have tested it at my end and is working fine. It will take columns specific to a view and not the ones which you have added from gear icon.


If you want the columns which are present on the list layout then make the view as empty



Script


function downloadPdf(){



  var checked = g_list.getChecked(); // get's the sys_id of the checked records


  var query = "sys_idIN" + checked.toString();


  var rows = checked.split(",").length; // rows to be sent to the pdf function


  var view = "default"; // set this to default for columns present in default view for list layout


  //var view = ""; // set this to empty if you want all the columns present in the list layout including the customized ones.



  var dialog = new GwtPollDialog('u_sample_table', query, rows, view, 'unload_pdf');


  dialog.execute();


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

28 REPLIES 28

Hi Trinadh,



Can you add an alert to check whether you are getting the sys_ids correct. For me it is working fine



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,


It worked well.I havent checked my table name.



Thank you,


Trinadh


Hi Trinadh,



Could you mark the answer as correct? Also mark helpful and hit like. Thanks in advance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,


The Ui button is working fine on the list choice.Now I want a seperate UI action on the form,that generates the PDF of that particular form.



I have modified the changes from the list and this is not working.


So,how should I modify the rows 'variable'





function downloadPdf(){



  var checked = g_form.getUniqueValue(); // get's the sys_id of the checked records


  var query = "sys_idIN" + checked.toString();


  alert(query);


  var rows = 1; // rows to be sent to the pdf function


  alert(rows);


  var view = "default"; // set this to default for columns present in default view for list layout


  //var view = ""; // set this to empty if you want all the columns present in the list layout including the customized ones.



  var dialog = new GwtPollDialog('u_table', query, view, 'unload_pdf');


  dialog.execute();


}




Thanks,


Trinadh


Hi Trinadh,



I am using script similar to yours and it is working fine for me on form. Can you add some alert messages?


Check table name etc



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader