<< Click to Display Table of Contents >> Obtain the file name of an uploaded file |
In many situations it is desirable to obtain the name of a file previously uploaded in order to perform different actions, for instance, validate if the file has an specific extension, number of characters etc.
To obtain the name of a file uploaded you must create an expression. In it obtain the list of files uploaded in a file-type attribute and go through each record of the array and extracting the name of each one.
The following expression shows how the name of a file stored in the Documents file-type attribute (from the Business Opportunity entity) is obtained supposing there is only one file updated in it. The name obtained is then displayed to the user through a validation message by using the CHelper.ThrowValidationError function. This expression is executed when Save is clicked in the form of a task for testing purposes.
//Obtain array of files
var UploadedFile = Me.getXPath("BusinessOpportunity.RelatedDocuments");
//Validate there are files in the array
if(UploadedFile.size() > 0){
//Obtain the file. Remember we assumed there is only 1, so the position of the array is 0
var Filename = UploadedFile.get(0).getXPath("FileName");
// Show the Filename
CHelper.ThrowValidationError("File name =" + Filename);
}
From the Work Portal in the form where the expression was configured, you can validate the file name is correctly returned.
Last Updated 1/6/2022 4:17:57 PM