How can I replicate Export as Excel in incident from list view?

ashwanikumar
Tera Expert

Hi All,

Is it possible to create a new custom UI Action on incident list view to replicate Export as an Excel?

If yes then how can I proceed?

Thanks,

Kumar

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ashwani,



yes you can.


You want it to export all the records or only the ones which user has selected from the checkbox.



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

Hi Ankur,

Only the ones which user has selected from the checkbox.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ashwini,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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

shanawazkhan9sh
Tera Contributor

Hi Ashwani,



This is possible you can use the below code in custom UI action under list view to achieve the same.



Steps:



Create a UI Action of List Choice Type,



find_real_file.png


Use the below code in script field.



function exporttoExcel() {



                              var sysparm_rows = g_list.grandTotalRows;


                              var num_rows = parseInt(sysparm_rows);


                           


                              var selSysIds = g_list.getChecked(); // This will return the sys_id of the selected records


                              var sysIdList = selSysIds.split(',');


                           


                           


                           



                              var sysparm_query = "";


                              for(var i=0;   i<sysIdList.length; i++) {


                                                              if(sysparm_query   != "") {


                                                                                              sysparm_query =   sysparm_query +"^OR" +"sys_id=" +sysIdList[i]; // Passing sys_ids to sysparm_query


                                                              }   else {


                                                                                              sysparm_query =   "sys_id=" +sysIdList[i];


                                                              }


                                                           


                              }


                           



                              var tableName = 'incident'; // Table Name for which the records needs to be exported


                              var sysparm_view = g_list.view;


// If the records are less then export threshold   GwtPollDialog will export the records in .xls format



                              if (num_rows < g_export_warn_threshold) {


                                                              var dialog = new GwtPollDialog(tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_excel_xls');


                                                              dialog.execute();


                                                              return;


                              }


// If the records are more then   export threshold GwtExportScheduleDialog will export the records in .xlsx format



                              var dialog = new GwtExportScheduleDialog(tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_excel_xls');


                              dialog.execute();


}