- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 07:42 AM
How to modify the OOB report page to add button "Export to Excel" similar to "Export to PDF"?
Solved! Go to Solution.
- Labels:
-
Analytics and Reports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 09:33 AM
Hello Rajput,
I was able to create an export to Excel button that would appear on every report next to the Export to PDF button. So you need to create a global UI SCRIPT and paste the code given below. Works great for those that do not want to do 2 clicks (and hover-over) to get the excel report.
Details:
- Button is located next to the Export to PDF Button.
- Takes a bit longer to load since is not included in source.
- Does not export graphs,am currently working on it. The button disappears if the graph type is selected.
- I still could not get the total rows of the report if grouped. If the report has a "Group by" filter then the scripts gets
the total rows of the grouped report (could say 30 but in reality has > 50000) so this will automatically download the report
without asking to mail it. Works fine with no "Group by" filters.
- Anyone who wants to point to errors or contribute, welcome!
Script Type: Global UI Script
Code:
/*
*-----------------------------------------------------------------------------------------------------------------
* BEGIN UI-SCRIPT
*-----------------------------------------------------------------------------------------------------------------
*/
addLoadEvent(addExportXLButton);
function addExportXLButton(){
//Create the button if the PDF export button exists and if the report is of type "list"
if($('export_pdf_button') && (gel('sysparm_type').value == 'list') ){
//Creates element type
var sp1 = document.createElement('button');
//Assigns id
sp1.id = 'export_excel_button';
//Names the button
sp1.innerHTML = 'Export to Excel';
//Button attribute value
sp1.setAttribute('value', 'Export to Excel');
//Executes the function "runContextAction()" when the button is clicked
sp1.setAttribute('onclick','runContextAction()');
//Sets element type
sp1.setAttribute('type', 'button');
//obtains element value
var sp2 = document.getElementById('export_pdf_button');
//Parents the export to PDF button
var parentDiv = sp2.parentNode;
//Inserts our button next to its parent "Export to PDF"
parentDiv.insertBefore(sp1, sp2.nextSibling);
}//End of If statement
}//End of addExportXLButton() function
function runContextAction() {
//Obtains the rows number of the current report
var sysparm_rows1 =$$('.list_row_number_input span')[1].innerHTML;
//Parses string value into an integer value
var num_rows = parseInt(sysparm_rows1);
//Gets report query
var sysparm_query = gel('sysparm_query').value;
//Get view name needed to export
var sysparm_view =gel('sysparm_view').value;
//Creates export file if rows is less than limit value
if (num_rows < g_export_warn_threshold) {
var dialog = new GwtPollDialog(gel('sysparm_table').value, sysparm_query, sysparm_rows1, sysparm_view, 'unload_excel');
dialog.execute();
return;
}//End of IF statement
//Else Asks user to mail report or wait for it
var dialog = new GwtExportScheduleDialog(gel('sysparm_table').value, sysparm_query, sysparm_rows1, sysparm_view, 'unload_excel');
dialog.execute();
}//End of runContextAction() function
/*
*-----------------------------------------------------------------------------------------------------------------
* END UI-SCRIPT
*-----------------------------------------------------------------------------------------------------------------
*/
Let me know if it worked on your end, I just have done this on ServiceNow Eureka and I have not tested this out in other releases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 09:33 AM
Hello Rajput,
I was able to create an export to Excel button that would appear on every report next to the Export to PDF button. So you need to create a global UI SCRIPT and paste the code given below. Works great for those that do not want to do 2 clicks (and hover-over) to get the excel report.
Details:
- Button is located next to the Export to PDF Button.
- Takes a bit longer to load since is not included in source.
- Does not export graphs,am currently working on it. The button disappears if the graph type is selected.
- I still could not get the total rows of the report if grouped. If the report has a "Group by" filter then the scripts gets
the total rows of the grouped report (could say 30 but in reality has > 50000) so this will automatically download the report
without asking to mail it. Works fine with no "Group by" filters.
- Anyone who wants to point to errors or contribute, welcome!
Script Type: Global UI Script
Code:
/*
*-----------------------------------------------------------------------------------------------------------------
* BEGIN UI-SCRIPT
*-----------------------------------------------------------------------------------------------------------------
*/
addLoadEvent(addExportXLButton);
function addExportXLButton(){
//Create the button if the PDF export button exists and if the report is of type "list"
if($('export_pdf_button') && (gel('sysparm_type').value == 'list') ){
//Creates element type
var sp1 = document.createElement('button');
//Assigns id
sp1.id = 'export_excel_button';
//Names the button
sp1.innerHTML = 'Export to Excel';
//Button attribute value
sp1.setAttribute('value', 'Export to Excel');
//Executes the function "runContextAction()" when the button is clicked
sp1.setAttribute('onclick','runContextAction()');
//Sets element type
sp1.setAttribute('type', 'button');
//obtains element value
var sp2 = document.getElementById('export_pdf_button');
//Parents the export to PDF button
var parentDiv = sp2.parentNode;
//Inserts our button next to its parent "Export to PDF"
parentDiv.insertBefore(sp1, sp2.nextSibling);
}//End of If statement
}//End of addExportXLButton() function
function runContextAction() {
//Obtains the rows number of the current report
var sysparm_rows1 =$$('.list_row_number_input span')[1].innerHTML;
//Parses string value into an integer value
var num_rows = parseInt(sysparm_rows1);
//Gets report query
var sysparm_query = gel('sysparm_query').value;
//Get view name needed to export
var sysparm_view =gel('sysparm_view').value;
//Creates export file if rows is less than limit value
if (num_rows < g_export_warn_threshold) {
var dialog = new GwtPollDialog(gel('sysparm_table').value, sysparm_query, sysparm_rows1, sysparm_view, 'unload_excel');
dialog.execute();
return;
}//End of IF statement
//Else Asks user to mail report or wait for it
var dialog = new GwtExportScheduleDialog(gel('sysparm_table').value, sysparm_query, sysparm_rows1, sysparm_view, 'unload_excel');
dialog.execute();
}//End of runContextAction() function
/*
*-----------------------------------------------------------------------------------------------------------------
* END UI-SCRIPT
*-----------------------------------------------------------------------------------------------------------------
*/
Let me know if it worked on your end, I just have done this on ServiceNow Eureka and I have not tested this out in other releases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 10:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 11:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 12:45 PM
Thanks David for sharing this!!