Question
Santander
BR
Last activity: 29 Aug 2018 17:25 EDT
How can create file type .txt ?
I need create a file type .txt automatic in Pega 7.3
Exist a activity OOTB to make this file ?
***Edited by Moderator Marissa to update categories***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
GB
Consider this approach:
1. Create an instance of a 'Rule-Obj-HTML' Rule ("Technical>HTML" from Designer Studio).
Use JSP syntax in this Rule-Obj-HTML to output the content; for instance:
Your Operator ID is:<pega:withPage name="OperatorID"><pega:reference name=".pyUserIdentifier" mode="text"/></pega:withPage>
2. Create An Activity, that uses the 'Property-Set-HTML' method (to render the JSP tags) to set a "Local Variable" called (say) 'TextFileContent' - (Defined on the 'Parameters' tab of the Activity, of Data Type 'String')
Once you had captured the rendered version of file into a Local Variable; use the following Public API in a Javastep:
try {
String result=tools.sendFile( TextFileContent.getBytes("UTF-8"), "MyTextFile.txt",false,null,true );
}
catch(Exception e) { oLog.error( e ); }
[ For Docs: See Help > Engine API to bring up the Javadocs; then locate the class "PublicAPI" ]
Consider this approach:
1. Create an instance of a 'Rule-Obj-HTML' Rule ("Technical>HTML" from Designer Studio).
Use JSP syntax in this Rule-Obj-HTML to output the content; for instance:
Your Operator ID is:<pega:withPage name="OperatorID"><pega:reference name=".pyUserIdentifier" mode="text"/></pega:withPage>
2. Create An Activity, that uses the 'Property-Set-HTML' method (to render the JSP tags) to set a "Local Variable" called (say) 'TextFileContent' - (Defined on the 'Parameters' tab of the Activity, of Data Type 'String')
Once you had captured the rendered version of file into a Local Variable; use the following Public API in a Javastep:
try {
String result=tools.sendFile( TextFileContent.getBytes("UTF-8"), "MyTextFile.txt",false,null,true );
}
catch(Exception e) { oLog.error( e ); }
[ For Docs: See Help > Engine API to bring up the Javadocs; then locate the class "PublicAPI" ]
Sample Output Attached.
Pegasystems Inc.
GB
Do you want to create a 'file.txt' on the server ? Or as an attachment - or perhaps just stream a text-file back to the user ?
Also - do you want to create a *dynamic* 'file.txt' - or simply stream a fixed file back ?
(The 'Engine API' provides mechanisms for creating and streaming files for instance; also check out the method 'Show-Stream' that be used from an Activity)
Santander
BR
Hi John,
I need create file.txt and send file back to the user.
Also i need create a *dynamic* 'file.txt' and stream a fixed file back
Thanks
Accepted Solution
Pegasystems Inc.
GB
Consider this approach:
1. Create an instance of a 'Rule-Obj-HTML' Rule ("Technical>HTML" from Designer Studio).
Use JSP syntax in this Rule-Obj-HTML to output the content; for instance:
Your Operator ID is:<pega:withPage name="OperatorID"><pega:reference name=".pyUserIdentifier" mode="text"/></pega:withPage>
2. Create An Activity, that uses the 'Property-Set-HTML' method (to render the JSP tags) to set a "Local Variable" called (say) 'TextFileContent' - (Defined on the 'Parameters' tab of the Activity, of Data Type 'String')
Once you had captured the rendered version of file into a Local Variable; use the following Public API in a Javastep:
try {
String result=tools.sendFile( TextFileContent.getBytes("UTF-8"), "MyTextFile.txt",false,null,true );
}
catch(Exception e) { oLog.error( e ); }
[ For Docs: See Help > Engine API to bring up the Javadocs; then locate the class "PublicAPI" ]
Consider this approach:
1. Create an instance of a 'Rule-Obj-HTML' Rule ("Technical>HTML" from Designer Studio).
Use JSP syntax in this Rule-Obj-HTML to output the content; for instance:
Your Operator ID is:<pega:withPage name="OperatorID"><pega:reference name=".pyUserIdentifier" mode="text"/></pega:withPage>
2. Create An Activity, that uses the 'Property-Set-HTML' method (to render the JSP tags) to set a "Local Variable" called (say) 'TextFileContent' - (Defined on the 'Parameters' tab of the Activity, of Data Type 'String')
Once you had captured the rendered version of file into a Local Variable; use the following Public API in a Javastep:
try {
String result=tools.sendFile( TextFileContent.getBytes("UTF-8"), "MyTextFile.txt",false,null,true );
}
catch(Exception e) { oLog.error( e ); }
[ For Docs: See Help > Engine API to bring up the Javadocs; then locate the class "PublicAPI" ]
Sample Output Attached.
-
Bhanu Prathap Kesamreddy Dhanushka Udayanga
Pegasystems Inc.
GB
Also: you may not wish to 'crush' the Exception Condition as I did in the code above; you could re-throw instead , like this:
try {
String result=tools.sendFile( TextFileContent.getBytes("UTF-8"), "MyTextFile.txt",false,null,true );
}
catch(Exception e) { throw new PRRuntimeException(e); }
Accenture Brazil
BR
Hi,
I tried your code and it freezed inside the try{}. So, I can create a .txt file with the TextFileContent inside, but after that my case just freezes inside this activity and dont proceed to the next step or stage. I tried a lot of things like a step End Activity and didn't work. Do you have any idea about what could be the problem or what line of code is missing in order to finish the activity?
Thanks,
Vitor
Pegasystems Inc.
GB
Are you sure the Activity is frozen ? Or do you just see lack of activity on the Browser ?
Did you take a thread dump of the JVM to see the Activity 'stuck' in a loop or something ?
Accenture Brazil
BR
Yes, it is freezing and the case is not progressing to the next step. PSA the print screens I've got after having the issue. Tracer shows the Activity has begun but not ended. I actually solved it by creating a Button that calls the Activity, then the case continues running without problems. But I would like to just submit my Assignment and then having the Activity to work automatically.
Santander
BR
Thanks much
Customer Value Partners Inc
US
Hi,
Thanks for the solution. code worked for me, but i want to move the text file to a specific folder in server or local directory.
Could you help us with extending the code to work for our solution.
Thanks.
-
koushick khandyana Manohar Inturi