Downloading a CSV file using a command button

  • 12 February 2024
  • 4 replies
  • 108 views

Userlevel 3
Badge +7

Hi all,

Here’s how you can download a CSV file by using a Command in IFS Cloud.

We can easily achieve this by doing few adjustments in .client, .projection, .plsvc and .plsql files.
(change in the .plsql file can be done in the .plsvc file too)
 

It’ll look like this
Add the command into the page that you want and click on it.
It’ll get downloaded to your default download folder

 


 


Here’s that downloaded CSV file

 

Steps to achieve the above functionality 

.PLSQL File change
Here you’ll add a method.
Basically you have to create a CLOB file > convert it to a BLOB file > return it.

PROCEDURE Convert_to_Csv(
csv_data_blob_ OUT BLOB)
IS
csv_clob_ CLOB;
BEGIN
csv_clob_ := 'Header 1' || ',' || 'Header 2' || ',' || 'Header 3' || ',' || 'Header 4'|| CHR(10);

FOR rec_ IN 1..20 LOOP
csv_clob_ := csv_clob_ || 'THRULK'||rec_ || ',' || 'THRULK'||rec_ || ',' || 'THRULK'||rec_ || ',' ||
'THRULK'||rec_ || CHR(10);
END LOOP;

csv_data_blob_ := Utility_sys.Clob_To_Blob(csv_clob_);
END Convert_to_Csv;

.Projection File Change
Defining a function which is returning a STREAM type value.
You can play around here by adding parameters to this function too.

function DownloadCsvFile Stream {
supportfileinfo = [true];
}

.PLSVC File Change
Implementing the above function.
You can set the file name, file type etc.
After that you have to call the above method in the .PLSQL file which is returning a BLOB file.

FUNCTION Download_Csv_File___  RETURN Stream_Data_Rec
IS
ret_ Stream_Data_Rec;
export_blob_ BLOB;
BEGIN
ret_.file_name := 'Sample' || '.csv';
ret_.mime_type := 'text/comma-separated-values';

Dbms_lob.Createtemporary(ret_.stream_data, FALSE);

C_Count_Reason_API.Convert_to_Csv(export_blob_);

ret_.stream_data := export_blob_;
RETURN ret_;
END Download_Csv_File___;

.Client File change
Here you’ll add a command and call that function in the Projection. You can directly call like this

command DownloadCsvCommand {
label = "Download CSV";
execute {
download "DownloadCsvFile()";
}
}

That’s it 😎

 


4 replies

Userlevel 4
Badge +9

Great and now, what would be a way to do the opposite? Upload a file to load data into a screen? (So not useing migration jobs, but just a csv file, have some upload screen, show the lines in a table view and then an action button which for examples pushes all the lines using an API?

Userlevel 4
Badge +9

@tharindukshan really liked your idea here any ideas how to do the opposite?

Userlevel 3
Badge +7

Hi @kvbe ,

One of my friends will create a post for that too.
He’ll share that here once that’s done.
 

Userlevel 3
Badge +7

Hi @kvbe 

Please refer this 


 

Reply