Question
Pegasystems
Last activity: 9 Sep 2016 1:13 EDT
Generate a CSV file from a pagelist and attach it to the case. (it should not popup for download
Hi Friends,
I have a requirement of generating a CSV file from a pagelist and attaching it to the case. It should not show popup for download.
I have tried using "pxConvertResultsToCSV" activity but it shows a popup to download, also it hangs the screen.
Any suggestion will be deeply appreciated...
Regards
Abhishek
-
Like (0)
Prasanna Kumar Badri -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems
Hi Patrick and PritJ,
Got it working…
Pega expects all the data encoded to Base 64 format. There was no problem with my data. When I click on the link of the attachment in pega to download or view the file, Pega runs a Final activity called “Work-.DisplayAttachFile”. This activity calls a function “SendFile” to send the file data. The 3rd parameter of this function is “aIsBase64Encoded” (data in base64 encoded format) and this final activity is passing this parameter as “true”.
Now we can’t change the Final activity so before I pass “Local.SCVString” as pyAttachStream, I am encoding it with “@(Pega-RULES:Default).Base64Encode(Local.CSVString)” and setting the encoded value as pyAttachstream of my attachment page.
Now it is working…..
Thanks a ton for your suggestions and help....
Regards
Abhishek
Pegasystems Inc.
SG
You'll need to write a custom activity that does everything in pxConvertResultsToCSV Steps 1 and 2. However, you will replace step 3 of the activity with steps that attach the document and link it to the work object
The download popup is the behaviour of step 3 of pxConvertResultsToCSV.
Regards
Patrick
Pegasystems
Thanks Patrik,
I tried replacing the step 3 to attach to the case, but could not make it work... Any suggestions or screenshot will help me...
Thanks a ton...
Abhishek
Pegasystems Inc.
GB
You might be able to salvage parts of this post : https://collaborate.pega.com/question/how-create-zip-archive-and-attach-case with regard to how to generate an attachment from file data.
Pegasystems Inc.
GB
Also : perhaps your code is working - but you need to issue an explicit "Commit" in your test Activity - to make sure the Attachment Page is saved ?
(Avoid the use of Explicit Commit if you can - instead try and embed your Activity (as a 'Utility') in a Flow which should result in stuff being committed to the Database at the right point of time).
Pegasystems
Hi PRITJ,
Thanks for your response, I am now able to attach the CSV to the case but the data in the file seems to be corrupted... Any solution?
Thanks and Regards
Abhishek
Pegasystems Inc.
SG
I don't have a working sample available, if not I could have shown you. What you have to understand is that your file is in memory at the end of step 1 of pxConvertResultsToCSV. Specifically it's in the local variable CSVString. Look at Step 2 to see if any specific manipulation is being done to this in memory file data to ensure you are attaching a valid file.
Once you know you have a valid file in memory, you need to set it to the property pyAttachStream of a clipboard page of class Data-WorkAttach-File (your attachment page) before saving it. Simply saving an attachment isn't enough as you need to create and save a link (clipboard page of class Link-Attachment) that links the work object and the attachment. The work object needs to be updated with this link information as well.
Use Work-.Attachfile as reference on creating all the pages required. Reference to "FileData" at the bottom of Step 6 is the equivalent of your "CSVString". FileData contains user uploaded file data in a hashmap. In your case there is no uploaded file only the generated CSV file. Just so there's no confusion, CSVString and FileData are equivalent in usage in this scenario, one contains file from an upload while the other contains a generated file.
I don't have a working sample available, if not I could have shown you. What you have to understand is that your file is in memory at the end of step 1 of pxConvertResultsToCSV. Specifically it's in the local variable CSVString. Look at Step 2 to see if any specific manipulation is being done to this in memory file data to ensure you are attaching a valid file.
Once you know you have a valid file in memory, you need to set it to the property pyAttachStream of a clipboard page of class Data-WorkAttach-File (your attachment page) before saving it. Simply saving an attachment isn't enough as you need to create and save a link (clipboard page of class Link-Attachment) that links the work object and the attachment. The work object needs to be updated with this link information as well.
Use Work-.Attachfile as reference on creating all the pages required. Reference to "FileData" at the bottom of Step 6 is the equivalent of your "CSVString". FileData contains user uploaded file data in a hashmap. In your case there is no uploaded file only the generated CSV file. Just so there's no confusion, CSVString and FileData are equivalent in usage in this scenario, one contains file from an upload while the other contains a generated file.
You can't use Attachfile directly as it assumes that the file to be attached has been uploaded by the user. This is shown in step 6. Essentially you will be replacing the functionality in Step 6 with steps to set your own file data to the attachment page. But the rest of the steps are needed to complete the file attachment and linking to workobject (case).
Hope this helps.
Regards
Patrick
Pegasystems
Thanks a lot Patrick,
I have commented step 3 of the activity and setting pyAttachStream property of the attachment page to "Local.CSVString" and then linking it to the case. Now I am able to attach the file to the case but the data gets corrupted. Any suggestions.....?
Regards
Abhishek
Pegasystems Inc.
SG
Could you explain what you mean by data gets corrupted? Can you share the snippet of code where you do the attachment?
Accepted Solution
Pegasystems
Hi Patrick and PritJ,
Got it working…
Pega expects all the data encoded to Base 64 format. There was no problem with my data. When I click on the link of the attachment in pega to download or view the file, Pega runs a Final activity called “Work-.DisplayAttachFile”. This activity calls a function “SendFile” to send the file data. The 3rd parameter of this function is “aIsBase64Encoded” (data in base64 encoded format) and this final activity is passing this parameter as “true”.
Now we can’t change the Final activity so before I pass “Local.SCVString” as pyAttachStream, I am encoding it with “@(Pega-RULES:Default).Base64Encode(Local.CSVString)” and setting the encoded value as pyAttachstream of my attachment page.
Now it is working…..
Thanks a ton for your suggestions and help....
Regards
Abhishek