0

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();
  }

Code replicate Export as Excel in incident from list view ServiceNow
Working Code Asked question December 20, 2024