The pui.download() API:
In this example, we will pass a string that contains parameters into the id property of pui.download().
An example of the string that we are passing is below:
In our exit program, we will be looking for “generatePDF” and if it is found, we will extract the parameters and pass them into an external program that will generate a PDF.
*One thing to note about the id property is that you can pass any string or “key” value. In your download exit program, you can look for the string or “key” value and call other programs or create temporary files.
The PUIDNLEXIT Program:
Below is the PUIDNLEXIT program we set up for this example in its entirety:
We won’t go into detail about the parameters set in this exit program. You can learn more about the different parameters for the PUIDNLEXIT program in the documentation. It’s also important to note that we did not change any of the parameters in the PUIDNLEXIT program we used for this, we kept them the same as they were in the sample PUIDNLEXIT program that is shipped with Profound UI.
The changes that we made are the following:
- We added a data structure named myFile. This will be passed to an external program that will provide it with the directory, filename, and attachment name of the PDF that is generated.
- We added an array called myParams which will contain the extracted parameters from the value passed into the id property of pui.download().
- We added a procedural interface for a custom external program that will generate a PDF depending on the parameters in the array that is passed.
- We added a sub procedure that will extract the parameters from the string that is passed using “:” as a delimiter.
In our exit program, we will check if the string that is passed in starts with “generatePDF”, and if it does, we will then try to extract the trailing parameters. If we have successfully extracted the parameters, we will pass the parameters array and the myFile data structure to an external program. The external program will generate a PDF and populate the fields in the data structure with the appropriate directory, file name, and attachment name for the file in the IFS.
After we received the populated data structure, we will need to set the following fields with the information in the data structure so that the browser can download the correct file:
- stmfDir – the directory of the file in the IFS.
- stmfName – the file name of the file.
- attName (Optional) – the attachment name of the download.