It is possible that a you need to validate the name of a file when it is being uploaded.
Suppose that a company is being audited. Each of the company areas must submit several reports to the audit company. In order to keep order in the reception and query of the information submitted in file format, the names of these files have to be predefined.
For example, the Financial Area of a Company must attach the financial balance in a excel file with the name Company Balance.xls.
In order to pre-define the names of the files to be attached we can use vocabularies. For more information about vocabularies please refer to Vocabularies.
In this case we define a string vocabulary. Its name will be BALANCE and its value will be Company Balance.xls (the desired file name).
In the Activity Form where the file is uploaded we can define the desired properties for the file. Click on the file attribute and then, in the Properties menu. Define the maximum number of files allowed and the valid file extensions. In this case we only allow one file to be uploaded. Only Microsoft Excel files will be able to be attached so we type xls in the valid extensions field.
A business rule is created to validate the name of the file. The expression is created On Exit of the Activity.
// Store the vocabulary definition
var UploadedFile = Me.getXPath("Process.Attribute");
// Store the filename in the attribute set aside for this purpose
var TargetFile = UploadedFile.get(0); var FileName = TargetFile.getXPath("FileName");
// Validate real versus desired file name
CHelper.ThrowValidationError("The file must have the same name of the vocabulary")
In the previous example we stored the vocabulary definition (pre-defined name of the file) in the DesiredFileName variable. Then we get the name of the uploaded file in the activity and we store it in the FileName variable. Finally we compare the values of both DesiredFileName and FileName variables and if they are not equal a message error is thrown.
This way if you attach a file with a no valid name, a message will be displayed and you will have to update a new file with the correct name.