UI-Action for Export List Data and mark them as "exported"

Stephan S_
Tera Expert

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

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

View solution in original post

19 REPLIES 19

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

Hi Ankur,

 

Thanks a lot for your very quick reply!

I had no chance to have a look at it. I'll give you Feedback soon.

 

Cheers

Stephan

Hi,

Is there a way to change the cells format when exporting to CSV using UI action? 

I know that the default is General and I need it to be Number.

Create a specific view on that list view with the columns you want to show, then update that list view name into the view variable that was provided in the code from Ankur