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

This was super helpful. Thank you so much!

Hello @Ankur Bawiskar,

I have a requirement to export data into excel and on click of download it should directly open in Google Sheets.

Is this possible? We have Google Sheets Connections. 

If it is possible could you please suggest the way to achieve this? I was trying different ways but it was not working as expected. 

I was tried the above code in the UI context menu and it got recorded in sys_attachment table. And I tried processing that attachment using script include in the same context menu. But, before exporting the list, the script include was processing.

If I write different script which is running after exported the data, how I can redirect user to Google Sheets on click of download button(from previous script).

Could you please help me on this requirement. I was stuck on this from past one week!

Thanks for your time!

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!

LucileC
Tera Expert

Hello, I have the same goal but I want to mark the records as exported only if the user click on the download button on the popup. 
Can you tell me if and how it's possible to know if the user click on the download or on the cancel button ?

Hi,

somewhat trickier to achieve; possibly you will have to check any place where it mentions the download has kicked off

Regards
Ankur

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