I have a screen with some labels and their inputs, and the data is coming into the inputs through a GET Api method. I need a button “Export to excel” on my screen, that can export all the data on screen in excel format.
Hi @Aman Kumar Bhardwaj
If you are working in reactive the your button on click handler action is a client side action, and RecordListToExcel is not available at client side,
So you just need to create some logic here,
Create a server action and pass your list as input parameter which you want to export in list, and create a output variable of Binary data type and assign RecordListToExcel to this variable,
Use this server action in your button on click handler action and drag download widget over end then give file name and file content as output of your server action.
Below snapshots can help you.
I hope it'll help you,
ThanksDeep
HiThis is the server action:
I'm getting this error in RecordDataToExcel:
I am passing a input variable of the structure type that I got through the GET api response.Can you please help?Thankss.
Hi Aman,
That error indicates that you are passing a single record of "GetUserTemplateResponse" instead of a record LIST of "GetUserTemplateResponse".
I am glad I could help.
RecordListToExcel takes list type variable and you are using single record.
Hi, @Deepsagar Dubey @Diogo Reis
I need only one record of my API which is visible on the screen to be exported to excel.
So, How can i achieve this?
Create a List with a single record!!
Hi,
Add a button to your screen and use the build in widget to export the recordlist from your table that shows the API data to excel.
https://success.outsystems.com/documentation/how_to_guides/data/how_to_export_entity_data_to_excel/
Regards,
Daniel
Hi @Aman Kumar Bhardwaj,
Follow the below steps to get the data from API and download data in excel format.For demo I used hospital API.Get data from API using data action:
Apply filter if you have any to filter API data. In below I did on the Hospital Name using dropdown value:
Pass the ListFilter.FilteredList to RecordListToExcel as shown below:
Assign the output of RecordListToExcel to output variable(binary data ) of data action :
Download the excel using download node by passing the output variable(binary data ) of data action as shown below:
You can check the demo to see how it will work through below link.
https://personal-qmzjggmd.outsystemscloud.com/FilterAPI/Test2?_ts=638191306886001839
Oml is also attached for reference.
Regards
Krishnanand Pathak
Actually, I'm not getting a List type response form API.Can you provide any suggestions?
Thanks!
Create an Output variable of Record List type in your API method and as you saying your API will always return a single record then append this record in your List variable,
That's it, Then your issues will be solved,
Hi @Aman Kumar Bhardwaj ,Just create a local variable Record list of API response( like GetMedicalcollegesResponse Record List) datatype inside the data action.Then use list append and append the local variable. then pass it to RecordListToExcel.It should work.RegardsKrishnanand Pathak
Hi,It worked.Thanks!
The data in excel is coming in alphabetical order,Can I set the order that which column should come first?
You can use ListSort before RecordListToExcel.To sort the excel data.
This is allowing to sort the list rows by a specific data.But, I need to sort the Columns in the List as per any order.
You can define the columns by creating structure based on your requirement.But this will not be a dynamic.