Question
GovCIO
US
Last activity: 17 Sep 2018 9:13 EDT
Unable to open/download the PDF file by clicking the button again and again
Hi,
We have a requirement to show the PDF by making a Conn-REST call to DocuSign and bring the PDF data from the response. After getting the response, we need to prepare the PDF and allow the user to open/download it from a button click. Here are the steps followed.
1) UI -> Section -> Button -> onClick -> Refresh-This-Section -> Call GetPDF activity
2) From the above activity, we have a call to Connect-REST and capture the PDF bytes stream from DocuSign response into a Parameter. After getting the Parameter value, we call the below java code from the same activity and the Page-Remove step.
------
String FileBinaryContent= tools.getParamValue("PDFData");
String FileName=tools.getParamValue("PDFFileName")+".pdf";
byte[] sPDFDecoded = org.apache.commons.codec.binary.Base64.decodeBase64(FileBinaryContent.getBytes());
String result=tools.sendFile(sPDFDecoded,FileName,false,null,true);
---
Code is working fine when we click the button from the Review harness and PDF is opening for download. But the problem is like, if I click the same button again and again then I don't see the PDF gets generated though I see a flickering after button click. By the way we are using PRPC V7.2.2
Please suggest me a solution to resolve this issue.
Thanks,
Ravi Kumar
***Edited by Moderator Marissa to update platform capability tags***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
IN
Hi Ravi,
Please try the below approach and let me know if this helps:
Hi Ravi,
Please try the below approach and let me know if this helps:
Copy the JavaScript function shown below in the UserWorkForm. Then configure the run script on download link or button and call this function.
<script>
function downloadFile(activityName, className, applicationName, fileName, fileType){
var suURL = SafeURL_createFromURL(pega.u.d.url);
suURL.put("pyActivity", activityName);
suURL.put("pyClassName", className);
suURL.put('ApplicationName', applicationName);
suURL.put('FileName', fileName);
suURL.put('FileType', fileType);
var formEle = document.createElement('form');
formEle.id = "download_file";
formEle.method = "POST";
formEle.action = suURL.toURL();
if(pega.env.ua.webkit)
formEle.target = "";
document.body.appendChild(formEle);
formEle.submit();
document.body.removeChild(formEle);
}
</script>
Regards,
Vikash
GovCIO
US
Hi Vikash,
Thanks for the code. May I know what are all the parameters are mandatory in the above mentioned function?
Thanks,
Ravi Kumar.
GovCIO
US
Hi Vikash,
I tried with your code option. Data is not coming in the PDF and the PDF is blank though we are successful in calling it multiple times from button click.
Thanks,
Ravi Kumar.
Barclays
IN
Hello Vikash,
My application id based on mashup code and we have above script configured on one link when document is not present on server post activity execution attached end message gets shown on screen which replace current screen.
We don't want to show this message in separate tab as well like we don't want show this message at all.
Any idea what changes we can do in -- formEle.target = ""; ??
Pegasystems Inc.
US
Can you add one more action such as Refresh Harness/ Refresh Section and run the usecase.
GovCIO
US
Hi Rachit,
I did add the Refresh Harness but the system got hung after downloading the PDF. Tried to use the Refresh Section but no luck. Is there any other alternative to modify the java code to work as expected?
Thanks,
Ravi Kumar.
GovCIO
US
Another point I want to bring is like if I use "Run Activity" option then I can run the activity multiple times with multiple button clicks. But I would like to download the PDF in this option.
Thanks
Ravi Kumar.
GovCIO
US
Looks like I have resolved the issue with my code but the below steps are followed.
From the section -> OnClick event, I am calling the below.
1) Refresh-Section with my above mentioned activity where I get the PDF after Conn-REST
2) Run Activity by having a single step in it. That is "Wait" method for 2 sec.
3) FinishAssignment call
With these sequence of steps, my PDF gets generated with the above java code and system waits for 2 sec to finish the process and making a harness refresh with #3 from above. Hope no performance issues with this idea. Feel free to chime in.
Thanks,
Ravi Kumar.
IBM INDIA PVT LTD
US
Hi Ravi,
I'm also facing same issue. Can you provide the java code which you used or screen shots.
IBM INDIA PVT LTD
US
Hi Ravi,
I followed same 3 steps which you followed but no luck.
Could you please provide alternative solution
Thanks,
Kondal
Vodafone
IN
Hi Ravi,
I am able to replicate the scenario and compared the tracers too. I found reloadSection activity is not getting called asynchronously in non-working scenario, will provide any alternate solution workaround to this shortly.
IBM INDIA PVT LTD
US
Hi Naveen,
Could you please provide any alternative solution.
Thanks,
Kondal
CollabPartnerz
IN
Below code works fine
String FileBinaryContent= tools.getParamValue("PDFData");
String FileName=tools.getParamValue("PDFFileName")+".pdf";
byte[] sPDFDecoded = org.apache.commons.codec.binary.Base64.decodeBase64(FileBinaryContent.getBytes());
String result=tools.sendFile(sPDFDecoded,FileName,false,null,true);
-
Sreekantha Peta
IBM INDIA PVT LTD
US
Hi Raveendra,
Could you please provide the values for PDFData,PDFFileName parameters in above java code
Thanks,
Kondal