Question

Upload CSV File on UI from Data-Portal and then parse the CSV Records

Hi ,

I have a requirement where,

  1. User will upload a CSV file from section in Data-Portal class.
  2. Then the uploaded CSV file is parsed to number of rows present in it.

What approach should i follow. I did not found any OOB feature which can help.

I tried using pzMultiFilePath control for uploading CSV and then i am not able to understand how will i parse the file in Post Processing as file content are in encoded form in property dragDropFileUpload.pxResults(1).pyFileSource.

Also i tried to store file on server at specified location while uploading on UI and then use Service-File Listener to parse the file. But i do not know how in Pega i can achieve from UI to upload file at a specified location on server.

Let me know if any one has any ideas how can i proceed.

***Moderator Edit-Vidyaranjan: Updated Platform Capability***

Correct Answer
October 17, 2019 - 1:05am

Hi ,

I found a workaround for above requirement using control : pzFilePathWithForm on UI for File upload 

And in post processing a java step 

ClipboardPage primary = tools.getPrimaryPage();

 

try {

java.util.HashMap hmFileInfo = pega_rules_utilities.uploadFile(true);

String strFileData = (String)hmFileInfo.get("FileData");

String strFileName = (String)hmFileInfo.get("FilePath");

String strFileExtension = (String)hmFileInfo.get("FileExtension");

 

if(!strFileExtension.equalsIgnoreCase("CSV")){

primary.getProperty("pyFileName").addMessage(tools.getLocalizedTextForString("pyMessageLabel","pzCSVFileValidationMessage"));

pega.terminateActivity();

}

 

//byte[] tempBytes = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(strFileData);

//fileContent = new String(tempBytes);

    fileContent = new com.pega.pegarules.pub.util.Base64Util().decode(strFileData);

  

} catch (PRRuntimeException pre) {

tools.getThread().getThreadPage().putString("pyXMLStream", pre.toString());

pega.terminateActivity();

}

Thanks.

Comments

Keep up to date on this post and subscribe to comments

October 10, 2019 - 4:30pm

Hi,

you can refer/configure pxUploadCSVResults flow action to upload the file and parse the file. Which will copy the data to specified pagelist in post action parameters.

Thanks,

Deva

 

October 29, 2019 - 8:25am
Response to Deva_Prathapaneni

Hello Deva,

I do have the same requirement. Can you help me with detail steps on how to achieve this. I am able to see the results in the list but i want to store the results in to pxResults of list property so that i can bind it to RepeatGrid. I have implemented like below.

1. on click of button, called a local action - UploadCSVResults. In the Flow Action(UploadCSVResults), i have called "pxUploadCSVResults" section.

2. In the post processing, i have called an activity inside which i called the activity "pxUploadCSVResults" in one step.

With this i am able to see the results in list property, but it is not as expected.

Ex : I have a page list in work type. Let's say, work type is PurchaseRequest and page list is ItemList, with class of MyCo-MyApp-Data-Item. In this data class, we have ItemID, ItemName, and ItemHowMany, and ItemPrice. And we have a CSV file that will look like:

1001, Pen, 2, 1.0
1010, Eraser, 1, 0.5
1022, Keyboard, 1, 12.0
1030, Mouse, 2, 8.5

My expected output is :

pyWorkPage.ItemList.pxResults(1)(MyCo-MyApp-Data-Item)
pyWorkPage.ItemList.pxResults(2)(MyCo-MyApp-Data-Item)
pyWorkPage.ItemList.pxResults(3)(MyCo-MyApp-Data-Item)
pyWorkPage.ItemList.pxResults(4)(MyCo-MyApp-Data-Item)

With the above approach i am getting the output as 

pyWorkPage.ItemList(1)
pyWorkPage.ItemList(2)
pyWorkPage.ItemList(3)
pyWorkPage.ItemList(4)

I want to store the results to pxResults of list property. I tried to pass the step page while calling the "pxUploadCSVResults" activity inside the activity by specifying the pages&classes as ItemList - Code-Pega-List and ItemList.pxResults - MyCo-MyApp-Data-Item. But somehow it didn't work.

Appreciate if you can help me with the steps if you achieved this functionality.

October 29, 2019 - 6:15pm
Response to NagaRamesh

When we have pagelist property then pega will form the structure as itemlist(1) format. I am not sure why you need pxResults structure pxResults format generally will be used on toplevel pages or data pages. If you need pyworkpage.itemlist.pxresults then may be you can try passing parameters to activity as pagename should be pyworkpage.itemlist(Itemlist is page property in work class) and .pxResults as pagelist. 

October 17, 2019 - 1:05am

Hi ,

I found a workaround for above requirement using control : pzFilePathWithForm on UI for File upload 

And in post processing a java step 

ClipboardPage primary = tools.getPrimaryPage();

 

try {

java.util.HashMap hmFileInfo = pega_rules_utilities.uploadFile(true);

String strFileData = (String)hmFileInfo.get("FileData");

String strFileName = (String)hmFileInfo.get("FilePath");

String strFileExtension = (String)hmFileInfo.get("FileExtension");

 

if(!strFileExtension.equalsIgnoreCase("CSV")){

primary.getProperty("pyFileName").addMessage(tools.getLocalizedTextForString("pyMessageLabel","pzCSVFileValidationMessage"));

pega.terminateActivity();

}

 

//byte[] tempBytes = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(strFileData);

//fileContent = new String(tempBytes);

    fileContent = new com.pega.pegarules.pub.util.Base64Util().decode(strFileData);

  

} catch (PRRuntimeException pre) {

tools.getThread().getThreadPage().putString("pyXMLStream", pre.toString());

pega.terminateActivity();

}

Thanks.