Question
Euroclear
BE
Last activity: 18 Jul 2017 2:27 EDT
Write a file to an explicit path
Hi ,
I am trying to write a .csv file into an explicit path in my server - /m2/app/pega/Extract
I am customising the activity pxConvertResultsToCSV to do so.
In the java step i am trying to give the explicit filename but it is not writing.But writing to temp direcrtory works fine.
Could you please advice what am i missing here.
char sep = PRFile.separatorChar;
String CSVexportPath= "/m2/app/pega/Extract";
*** commented the existing logiv to write to temp directory ***
//String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
FileName+=fileNameParam;
if(appendTimeStamp){
FileName+="_";
FileName+=dtu.getCurrentTimeStamp();
}
FileName+=".csv";
String strSQLfullPath = CSVexportPath+ sep + FileName;
PRFile f = new PRFile(strSQLfullPath);
Message was edited by: Lochan to add Category
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Euroclear
BE
I have fixed it.It was becasuse of the directory permission.The application id was not the owner of the directory and hence it was not writing into it
Pegasystems Inc.
US
What is the complete java step for this? The original java step has something like this - which is responsible for writing out the file.
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);
//Close the output stream
out.close();
}catch (Exception e) {
oLog.error("Error writing csv file: " + e.getMessage());
}
Euroclear
BE
I have mentioned only the place where i have made a change.Rest all are the same as in the OOTB java code.
Pegasystems Inc.
US
ok, have you noticed any errors/exceptions in the logs? Suggest add debug statement (System.out is fine for your purpose) in the java step to trace where it can go wrong.
Euroclear
BE
Yeah i have tried it .It shows the correct path but it does not write it out.Also checked the permissions of the dircetory.All good.Not a clue whats happening
Pegasystems Inc.
US
I would try not to use any pega class (e.g., PRFile) and use generic java class to try. You should be able to find plenty of sample code over the internet.
Accepted Solution
Euroclear
BE
I have fixed it.It was becasuse of the directory permission.The application id was not the owner of the directory and hence it was not writing into it
Virtusa
IN
Hi Harish,
I am also facing the same issue ,could you please let me know how did you fix this and what is the Application ID here? and how to enable the access for the same. Thanks in Advance.
Pegasystems Inc.
IN
Hi Gulshan,
Thank you for posting your query on PSC. This looks like an inactive post and hence, we suggest you create a new post for your query. Click on the Write a Post button that’s available on the top right pane of this page. Once created, please reply back here with the URL of the new post.
We have also sent you a private message opening up a communication channel in case you have any further questions.
Thanks!
United Health group
IN
i have same kind of requirement, as mentioned i have hard coded my location and commented download file step.
but i am not able to see the file in location as i mentioned in the java step
char sep = PRFile.separatorChar;
//*String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
//*String exportPath = tools.getParamValue("FilePath");
String exportPath="Libraries/Documents";
DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
String fileNameParam = tools.getParamValue("FileName");
if(fileNameParam.equals("")){
fileNameParam = "RecordsToCSV";
}
Boolean appendTimeStamp = tools.getParamAsBoolean(ImmutablePropertyInfo.TYPE_TRUEFALSE,"AppendTimeStampToFileName");
i have same kind of requirement, as mentioned i have hard coded my location and commented download file step.
but i am not able to see the file in location as i mentioned in the java step
char sep = PRFile.separatorChar;
//*String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
//*String exportPath = tools.getParamValue("FilePath");
String exportPath="Libraries/Documents";
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);
//Close the output stream
out.close();
}catch (Exception e) {
oLog.error("Error writing csv file: " + e.getMessage());
}
Here the Highlited one is the step i have hard coded value.
i have seen the tracer events but no errror.
Could anyone please help me on this.
Thanks
-
Naoya Kurokawa MADDULURI VENKATA SAI KALYAN