Question
Accenture
IN
Last activity: 25 Sep 2024 10:02 EDT
Activity to place CSV file on server Path folder
Hi Team,
Need to convert Pagelist having pxResults to CSV and the CSV file should be available in server path.
Pls provide help
-
Reply
-
MADDULURI VENKATA SAI KALYAN -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Bits in Glass
IN
@KalyanMadduluri have you checked this url. This has the solution
https://support.pega.com/question/convert-pxresults-csv-and-place-server-path
First covert using pxConvertResultstoCsv. Then use the mentioned java code to place file on server path.
FYI-
If you use
1. pzInitAttachment
2. pyUploadFile
3. SaveAttachment
This will place file in service export directory.
Accenture
IN
@Anoop Krishna I tried the mentioned approach in the article which u provided but i am facing the error in java code in the function rule. I created the function rule as mentioned and created the library but when i saved the java code and save the function getting the below errors
"The method UploadFileToNetwork01_01_01(byte[], String, String, Int) from the type test_UploadFileToNetwork_010101_8808693506552754636 refers to the missing type Int
line: -18 Int cannot be resolved to a type
line: -1 Int cannot be resolved to a type
line: 7 Void methods cannot return a value
line: 11"
The approach i followed in the article is :
This worked for me after with minimal customization of OOTB activities
Step1: Customize the below two OOTB activities to your ruleset with your class names
Use OOTB pxDownloadDataRecordsAsCSV (Consider the steps from 6-8) to pull the records (Pass RD and Class Name as params). pxConvertResultsToCSV
Step2: Set the file location path from DDS ex: local.exportPathbefore the last java step.
Modify the Java code(Write to csv file at location java step) to write the .csv file to the location (You should have the access to the network path)
@Anoop Krishna I tried the mentioned approach in the article which u provided but i am facing the error in java code in the function rule. I created the function rule as mentioned and created the library but when i saved the java code and save the function getting the below errors
"The method UploadFileToNetwork01_01_01(byte[], String, String, Int) from the type test_UploadFileToNetwork_010101_8808693506552754636 refers to the missing type Int
line: -18 Int cannot be resolved to a type
line: -1 Int cannot be resolved to a type
line: 7 Void methods cannot return a value
line: 11"
The approach i followed in the article is :
This worked for me after with minimal customization of OOTB activities
Step1: Customize the below two OOTB activities to your ruleset with your class names
Use OOTB pxDownloadDataRecordsAsCSV (Consider the steps from 6-8) to pull the records (Pass RD and Class Name as params). pxConvertResultsToCSV
Step2: Set the file location path from DDS ex: local.exportPathbefore the last java step.
Modify the Java code(Write to csv file at location java step) to write the .csv file to the location (You should have the access to the network path)
char sep = PRFile.separatorChar; String status=""; //String exportPath= tools.getProperty("pxProcess.pyText").getStringValue(); DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
String fileNameParam = tools.getParamValue("FileName"); if(fileNameParam.equals("")){ fileNameParam = "RecordsToCSV"; } Boolean appendTimeStamp = tools.getParamAsBoolean(ImmutablePropertyInfo.TYPE_TRUEFALSE,"AppendTimeStampToFileName");
FileName+=fileNameParam; if(appendTimeStamp){ FileName+="_"; FileName+=dtu.getCurrentTimeStamp(); } FileName+=".csv"; String strSQLfullPath = exportPath+ sep + FileName; PRFile f = new PRFile(strSQLfullPath); try{ // Create file PROutputStream stream = new PROutputStream(f); PRWriter out = new PRWriter(stream, null, false); // Bug with Excel reading a file starting with 'ID' as SYLK file. If CSV starts with ID, prepend an empty space. if(CSVString.startsWith("ID")){ CSVString=" "+CSVString; } out.write(CSVString); byte[] bytes = CSVString.getBytes(); status = ABCD_utilities.UploadFileToNetwork(bytes, exportPath, FileName, 0 ); oLog.infoForced(status); //Close the output stream out.close(); }catch (Exception e) { oLog.error("Error writing csv file: " + e.getMessage()); }
Step 3: Custom function ABCD_utilities.UploadFileToNetwork
Input Parameters:
Name --> Java Type -->Pega Type
fileContent-->byte[]
networkLocation-->String-->Text
fileName-->String-->Text
maxFileSizeInMB-->Int-->Number
Java Code:
String status = null; networkLocation = networkLocation + "\\" + fileName; File file = new File(networkLocation);
/* Validate Inputs */ if ((networkLocation == null || networkLocation.equals("")) || fileName == null|| fileName.equals("") || fileContent == null) { status = "FAIL:F1-Upload failed due to missing information"; return status; }
int fileSize = fileContent.length/1048576;
/* Validate File Size */ if (maxFileSizeInMB > 0 && maxFileSizeInMB < fileSize) { status = "FAIL:F2-File size (" + fileSize + " MB) exceeded Max File Size Limit of " + maxFileSizeInMB + "MB"; return status; } try { ByteArrayInputStream inByteStream = new ByteArrayInputStream(fileContent); InputStream inStream = new BufferedInputStream(inByteStream); OutputStream outStream = new BufferedOutputStream(new java.io.FileOutputStream(file));
byte outBuffer[] = new byte[4096]; int len; while (( len = inStream.read(outBuffer)) != -1) { outStream.write(outBuffer, 0, len); } inStream.close(); outStream.flush(); outStream.close(); status = "SUCCESS:File Uploaded"; } catch (Exception ex) { oLog.error("Error writing uploaded file to Macess", ex); status = "FAIL:F99-Upload failed due to the following exception : " + ex.getMessage(); }
return status;
Bits in Glass
IN
@KalyanMadduluri Above approach worked for you?
Accenture
IN
@Anoop Krishna - No, i am facing issues when i try to save the function with java code that is given above
Bits in Glass
IN
@KalyanMadduluriokay, need to check then.