Custom Widget On Service Portal To Export Table To Excel?

JDX7913
Tera Guru

I am looking for a way to add a button to my custom widget to export all of the data on said table to excel.

For example, right now my custom widget goes to table "X" and from there it query all of the name, address, etc. and display that on my widget as a table. I want to provide the user with a button to export all of that to excel (similar to how backend user can do it in almost all table).

I found this link which shows how to create a custom button, but what do I put in the server script?

Thank you for the help. 

1 ACCEPTED SOLUTION

So I found a way to make it work.

On the client side script of a widget all you need is the following:

window.location.href = "/" + {table name} + .do?EXCEL&sysparm_query=" + {your encoded query} + 
					"&sysparm_fields=" + {field name of the columns from the table};

I hope this will help anyone else who is trying to do the same as I am.

Thank you.

View solution in original post

3 REPLIES 3

Priyanka Gupta
Mega Guru

Hi,

I am doing the same thing on Platform UI and this link has really helped me achieve what I wanted-

https://jsfiddle.net/shaswatatripathy/fo4ugmLp/1/

Hope this helps!

Priyanka

Thank you for your input, however, that is more for the UI policy (e.g. for backend use, not for service portal side). 

I looked around in the context menu and I found the code to export to Excel, however when I copied that to the client script of my widget I get the following errors.

find_real_file.png

If g_list is not available on the portal side then what do I use instead? 

Thank you for the help, thus far. 

So I found a way to make it work.

On the client side script of a widget all you need is the following:

window.location.href = "/" + {table name} + .do?EXCEL&sysparm_query=" + {your encoded query} + 
					"&sysparm_fields=" + {field name of the columns from the table};

I hope this will help anyone else who is trying to do the same as I am.

Thank you.