Hello All,
In this post let us try to put restriction on the Type of files while adding new Attachments.
The Logic is pretty simple,
1. Identify the Target Attachment BC
2. Identify the File Type Field
3. Write Script on PreWriteRecord of Business Component
In any attachment applet, we can see the Fields Name, Size (in Bytes) ,Type etc.
Lets Try to write a Piece of Code to fetch the Type of File:
The code below prevent to attach exe, msi or apk files that can be cause potential threats to system
function BusComp_PreWriteRecord () { var ext= GetFieldValue("FileExt"); //Get the File Extension switch(ext) { case "exe": TheApplication().RaiseErrorText("This Type of File is Not Allowed"); break; case "EXE": TheApplication().RaiseErrorText("This Type of File is Not Allowed"); break; case "msi": TheApplication().RaiseErrorText("This Type of File is Not Allowed"); break; case "apk": TheApplication().RaiseErrorText("This Type of File is Not Allowed"); break; case "APK": TheApplication().RaiseErrorText("This Type of File is Not Allowed"); break; default: //do nothing } } |
Error Popup on Save Record: