Question

File not instantly downloading when using PXRedirectToFileException

  • 25 April 2024
  • 1 reply
  • 19 views

I have a custom page that will allow a user to select several records from a grid and then click a ‘Generate Document’ button that will use a stored proc & several API calls in order to retrieve details from the selected records and generates a document using these details.

Each record has the ‘Selected’ property which handles the checkbox selection and lets the ‘Generate Document’ button know which records to pull the details from (using the Reference Number on each selected record).

I am using the ‘PXRedirectToFileException’ to download the file after the final API call returns the byte[] array that represents the generated document (and creating a new ‘FileInfo’ object using this byte[] array and a previously declared document name).

I don’t run into any errors when executing my code and interacting with the page but when I try to click ‘Generate Document’ there is a slight loading period and then nothing happens UNTIL I click another checkbox on any record and then the file is downloaded in the browser.

Here is a screenshot of the code that performs the API calls and returns the generated document (within a ‘PXLongOperation’ since I have to await all of the API calls) before calling PXRedirectToFileException.

 

 

This code is within the delegate method for the ‘Generate Document’ button. The ‘adapter.View.RequestRefresh();’ and ‘return adapter.Get();’ lines of code are called right away and don’t wait for the ‘PXLongOperation’ to finish which may be causing an issue but I don’t believe I can make the ‘generateDocument’ delegate method asynchronous.

 

I had a previous issue with the checkboxes getting cleared after clicking ‘Generate Document’ but I updated the view delegate method for the records to check the ‘Selected’ property as you can see in this foreach statement - 

 

I thought that getting the checkboxes to maintain their state before and after generating the document would help with getting the file to download immediately but I still have to click a checkbox in order for the file to be downloaded in the browser.

Not sure if I need to call some other ‘RequestRefresh’ type of method or something else to get the browser to recognize that a file is being downloaded? 

Here is what the page looks like after selecting two records, clicking the ‘Generate Document’ button, and waiting for the page loading to finish - 

 

Here is the page after unselecting the first record which causes the generated document to be downloaded in the browser (you can see the Reference Nbr’s in the file name for the selected records) - 

 

I have a feeling this issue is a result of calling a PXLongOperation within the delegate method and needing to call some sort of ‘RequestRefresh’ method only when the PXLongOperation finishes instead of the Refresh being called right away while the PXLongOperation still runs.

Welcome to any suggestions/assistance with this strange issue, thanks for any help in advance! 

 


1 reply

Update - I have the file downloading instantly now, I added a call to ‘PXLongOperation.WaitCompletion(UID)’ after the call to PXLong.StartOperation



But now my grid of results is getting cleared a few seconds after the file is downloaded, I think it has something to do with some code in the ‘records’ delegate method I posted in the original question - seeing if adding some sort of refresh call at the end of that method will help.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved