How to show a list of restricted file types to the user (based on File Extension List)

In my previous two posts I mentioned that we can use File Extension List to created (or store) a list of file extensions. This File Extension List can be used to reject or accept list of file types for users when uploading files to the PeopleSoft system. To refresh, please read following Posts if you are not sure what the File Extension List is?
How to restrict File Types (extensions) from URL Object Properties When Adding Attachments Part I
How to restrict FileTypes (extensions) from URL Object Properties When Adding Attachments Part II
Sometimes you want to show a message to users to explicitly say that our PeopleSoft system only accept certain list of file types when you doing file attachments. One of the easiest ways to generate this message is to get the list of file types from the File Extension List records. In this post, I assume that you have already created a File Extension List (PeopleTools > Utilities > Administration > File Extension List) and configure it as a URL properties for the file attachment record.

If all the configurations are done then you can access this file extensions by querying the underlying record PTFX_EXTLST.
You can create a PeopleCode function in which you can pass list Name (e.g. MY_TEST_FILE_EXTENSION) to the function dynamically and build the file list as shown in the following example.
/*this function will build the common file extension list for file upload*/
Function MyFileExtensionList(&ExtListName As string) Returns string
   
   Local string &FileExt;
   Local string &FileList = "";;
   Local SQL &FileList;
   rem get the file extension list from PTFX_EXTLST record (File List);
   &FileList = CreateSQL("SELECT DISTINCT A.PTFX_EXT FROM PS_PTFX_EXTLST A WHERE A.PTFX_EXTLST_NAME = :1 ORDER BY 1", &ExtListName);
   
   /*build the file extension list*/
   While &FileList.Fetch(&FileExt)
      &FileList = &FileList | ", " | &FileExt;
   End-While;
   
   &FileList = LTrim(&FileList, ", ");
   
   Return &FileList;   
End-Function;

This way you can show a message to user if they fail to attach a file which are not in this list
/*check the Return code for file extension validation*/
/*Retrun code 21 - "File transfer failed because the file extension is not allowed."*/
   If &numRetCode = 21 Then
      MessageBox(0, "", 0, 0, MyFileExtensionList("MY_TEST_FILE_EXTENSION"), 0);
   Else
/*all good*/
 End-If;

SHARE

Ayesha Wee

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment