- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 05:19 AM
Dear SN-Dev Community,
first i`d like to thank you! - I`m very new to SN. And I just started to work as Developer.
Your answers helpt me alot in the last few month. With your help I was able to create a UI-Action to Export some Data without a rightclick (Customerneeds 😃 )
Now my Customer needs an indicator to see if a row has beed exported. Therefore I`d like to Update the Case-State. But I am open to other suggestions like a new "exported" true/false field.
Both ("exported-flag" and Download of the Excel itself) have to be on the same UI-Button.
I tryed https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/ but was not able to solve my issue.
Could you please help out?
Here is my Export UI-Action:
function downloadExcel(){
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 export function
var view = "default"; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('sn_customerservice_case', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 05:33 AM
Hi Stephan,
create new boolean field Exported of type True/False
in the UI action code use this script to update the Flag as true;
also the UI action should be selected only for non-exported records so update UI action condition as
!current.u_exported
UI Action script code
function downloadExcel(){
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 export function
// this code you can move to script include and go GlideAjax as well
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id', 'IN', rows);
gr.query();
while(gr.next()){
gr.u_exported = true;
gr.update();
}
var view = "default"; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('sn_customerservice_case', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2024 10:10 AM
Hello Ankur Bawiskar,
I have a requirement to export data and on click of download button data should be opened directly in Google Sheets.
Is this Possible? We have Google Sheets Spoke Connections. I have tried different ways but, it was not working as expected.
I have tried the above code in the UI context menu and on export it got recorded in sys_attachment table. In the same UI context menu I have created a script include to process the downloaded attachment.
But while testing, script include was completed running and ignoring the exporting. If I comment the script include part then the exporting working fine but processing is not working.
Could you please suggest if any ways is there to achieve this functionality?
Thank you for your time!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 05:50 AM
Hey Steven, I am also trying to export a list of records and change their state to Exported.
What is GwtPollDialog?
Is this someting you've made custom? Would you mind sharing this script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 06:18 AM
Hi Harun,
here is a Screenshot from the Code. Below the Copy-Version.
GwtPollDialog is the part where the UI-Actions calls the SN-Standard Download-Popup-Thing 😃
function downloadExcel(){
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 export function
// this code you can move to script include and go GlideAjax as well
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id', 'IN', checked);
gr.query();
while(gr.next()){
gr.state = 6;
gr.update();
}
var view = ""; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('sn_customerservice_case', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 06:29 AM
Much appreciated Stephen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2020 07:43 AM
For some reason I can't get it to work Its just not executing. I have the onClick filled with the name of the function. I cant see what Im doing wrong.
downloadExcel();
function downloadExcel(){
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 export function
// this code you can move to script include and go GlideAjax as well
var gr = new GlideRecord('mycustomtable');
gr.addQuery('sys_id', 'IN', checked);
gr.query();
while(gr.next()){
gr.exported = true;
gr.update();
}
var view = "default"; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('mycustomtable', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}