Passing Parameters with pui.download()
Introduction:
In this example, weāll show you how to pass multiple parameters in the pui.download() API. For this example, we will be making use of theĀ pui.download()Ā API and theĀ PUIDNLEXITĀ program.
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:
"generatePDF:parm1:parm2:parm3:"
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:
Ā Ā Ā Ā **********************************************************************************************
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Description: Profound UI File Download Exit ProgramĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Compile as PUIDNLEXIT in PROFOUNDUI product library using CRTBNDRPG.Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Return 1 in 'Allow' parameter to allow the download, any other value willĀ Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā prevent the downloadĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā *Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā *
Ā Ā Ā Ā Ā **********************************************************************************************
Ā
Ā Ā Ā Ā D InputData_t Ā Ā Ā Ā dsĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā qualified
Ā Ā Ā Ā DĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā based(Template)
Ā Ā Ā Ā DĀ Ā fileidĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 640aĀ Ā varying
Ā Ā Ā Ā DĀ Ā useridĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 10a
Ā Ā Ā Ā DĀ Ā ipAddrĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 15a
Ā Ā Ā Ā DĀ Ā inlineĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 1n
Ā
Ā Ā Ā Ā D MainĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā PRĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ExtPgm('PUIDNLEXIT')
Ā Ā Ā Ā DĀ Ā timingFlagĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 10i 0 const
Ā Ā Ā Ā DĀ Ā inputDataĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā likeds(InputData_t) const
Ā Ā Ā Ā DĀ Ā stmfDirĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 640aĀ Ā varying
Ā Ā Ā Ā DĀ Ā stmfNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 256aĀ Ā varying
Ā Ā Ā Ā DĀ Ā attNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 256aĀ Ā varying
Ā Ā Ā Ā DĀ Ā contentType Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 255aĀ Ā varying
Ā Ā Ā Ā DĀ Ā allowĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 5i 0
Ā
Ā Ā Ā Ā D MainĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā PI
Ā Ā Ā Ā DĀ Ā timingFlagĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 10i 0 const
Ā Ā Ā Ā DĀ Ā inputDataĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā likeds(InputData_t) const
Ā Ā Ā Ā DĀ Ā stmfDirĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 640aĀ Ā varying
Ā Ā Ā Ā DĀ Ā stmfNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 256aĀ Ā varying
Ā Ā Ā Ā DĀ Ā attNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 256aĀ Ā varying
Ā Ā Ā Ā DĀ Ā contentType Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 255aĀ Ā varying
Ā Ā Ā Ā DĀ Ā allowĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 5i 0
Ā
Ā Ā Ā Ā D myFileĀ Ā Ā Ā Ā Ā Ā Ā Ā DSĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā qualified
Ā Ā Ā Ā DĀ Ā directoryĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā like(stmfDir)
Ā Ā Ā Ā DĀ Ā fileNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā like(stmfName)
Ā Ā Ā Ā DĀ Ā attachNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā like(attName)
Ā
Ā Ā Ā Ā d myParmsĀ Ā Ā Ā Ā Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 25AĀ Ā dim(3)
Ā Ā Ā Ā d fileGenerated Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā NĀ Ā inz(*off)
Ā Ā Ā Ā d extractedĀ Ā Ā Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā NĀ Ā inz(*off)
Ā
Ā Ā Ā Ā D generatePDFĀ Ā Ā Ā PRĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā N
Ā Ā Ā Ā D parametersĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 25AĀ Ā dim(3)
Ā Ā Ā Ā D fileInfoĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā likeds(myFile)
Ā
Ā Ā Ā Ā D extractParmsĀ Ā Ā PRĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā N
Ā Ā Ā Ā D fileIdĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā like(inputData.fileId) const
Ā Ā Ā Ā D parmsArrayĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 25AĀ Ā dim(3)
Ā
Ā Ā Ā Ā Ā /free
Ā Ā Ā Ā Ā Ā if %subst(inputData.fileId: 1: 11) = 'generatePDF';
Ā Ā Ā Ā Ā Ā Ā Ā extracted = extractParms(inputData.fileId: myParms);
Ā Ā Ā Ā Ā Ā Ā Ā if extracted = *on;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fileGenerated = generatePDF(myParms: myFile);
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā if fileGenerated = *on;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā stmfDir = myfile.directory;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā stmfName = myfile.fileName;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā attName = myfile.attachName;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā allow = 1;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā else;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā allow = 0;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā endif;
Ā Ā Ā Ā Ā Ā Ā Ā else;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā allow = 0;
Ā Ā Ā Ā Ā Ā Ā Ā endif;
Ā Ā Ā Ā Ā Ā endif;
Ā
Ā Ā Ā Ā Ā Ā *INLR = *on;
Ā Ā Ā Ā Ā Ā Return;
Ā Ā Ā Ā Ā /end-free
Ā
Ā Ā Ā Ā P extractParmsĀ Ā Ā B
Ā Ā Ā Ā D extractParmsĀ Ā Ā PIĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā N
Ā Ā Ā Ā D fileIdĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā like(inputData.fileId) const
Ā Ā Ā Ā D parmsArrayĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 25AĀ Ā dim(3)
Ā Ā Ā Ā D strStartIdxĀ Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 5I 0 inz(0)
Ā Ā Ā Ā D strEndIdxĀ Ā Ā Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 5I 0
Ā Ā Ā Ā D iĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 5I 0 inz(1)
Ā Ā Ā Ā D successĀ Ā Ā Ā Ā Ā Ā Ā S Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā NĀ Ā inz(*off)
Ā
Ā Ā Ā Ā Ā /free
Ā Ā Ā Ā Ā Ā Ā Ā strStartIdx = %scan(':': fileId: 1);
Ā Ā Ā Ā Ā Ā Ā Ā dou strEndIdx = 0;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā if (strStartIdx = 0) or ((strStartIdx + 1) > %len(fileId));
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā strEndIdx = 0;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā iter;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā endif;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā strEndIdx = %scan(':':fileId: strStartIdx + 1);
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā if strEndIdx = 0;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā iter;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā endif;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā parmsArray(i) =
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā %subst(fileId: strStartIdx + 1: strEndIdx - strStartIdx - 1);
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā i += 1;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā strStartIdx = strEndIdx;
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā success = *on;
Ā Ā Ā Ā Ā Ā Ā Ā enddo;
Ā Ā Ā Ā Ā Ā Ā Ā return success;
Ā Ā Ā Ā Ā /end-free
Ā
Ā Ā Ā Ā P extractParmsĀ Ā Ā E
Ā
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.
Ā
Ā
Ā