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

Hi Harun,

the line "gr.exported" is a custom column. Maybe you should remove this. Try the one setting the state or delete those rows:

while(gr.next()){
gr.state = 6;
gr.update();

Also (i guess you have it done, but for completness): have you clickt the rows to be exported?

Best Stephan

Hey Stephen,

Yes the exported is a custom column(true/false) in my app which I basically want to change if the script runs.

Because I want to mark if the record was exported when this UI Action was executed, and that would in turn remove it from the list as this list only shows records that were not exported yet.

Yes I have ticked the records which I wanted to export to Excel but nothing happened. Also thats how the getChecked() method works, it only retrieves the ticked records (from my understanding at least)

This is how the UI Action is configured

find_real_file.png

Hi Harun,

in Orlando i am getting the same issue... have you resolved it jet?

 

This is my error:

find_real_file.png

 

Hi, yes I have resolved this issue with the help from Ankur here.

https://community.servicenow.com/community?id=community_question&sys_id=9ab23c28dbce14107d3e02d5ca96198a

By the way this GwTPollMethod only works if your UI Action is set as a List Context Menu (i have that and List Banner Button ticked).

And make sure you call "downloadExcel()" function in onClick.

sajida
Kilo Explorer

@Stephen S.  

Can you please provide me the Script how you have  created a UI-Action to Export some Data without a rightclick