The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Saturday 9 March 2013

Working with Files and Attachments in PeopleSoft

When customizing PeopleSoft applications to meet the business requirements, you will frequently encounter situations where you need to handle files. Since peoplesoft is a database driven application and peoplecode is limited to application level coding, you might not find enough objects to handle files.

However peoplesoft has delivered some built in functions to handle files and attachments. I will give a glimpse on the usage of these functions. For detailed explanations you can visit the peoplebooks hosted by oracle.

Uploading File from end user machine to server

This is a frequent requirement when you are working with recruitment of staffing systems. You need to upload the resume files into the system.

PeopleSoft has delivered a built in function called AddAttachment() to handle this scenario.

Syntax: AddAttachment(URLDestination, DirAndFilePrefix, FileType, UserFileName[, MaxSize [, PreserveCase[, UploadPageTitle[, AllowLargeChunks]]]])


Th URL Destination will be the parameter which specifies the path in the server where you want to store the file. It can be a DB record, FTP URL, or app server URL. For detailed explanation you can refer peoplebooks.

Copying File from Storage to App Server

Sometimes you might need to copy a file from its storage location to app server to do the temporary processing. For example, if the file is stored in DB server, you cannot send the file as attachment using SendMail function. For that first you need to copy file from DB server to App Server and then send the mail. To deal with such situations, you can use the GetAttachment() function.

GetAttachment(URLSource, DirAndSysFileName, DirAndLocalFileName[, LocalDirEnvVar[, PreserveCase]])

&retcode = GetAttachment("",
"NewHire/11042000resume.txt", "c:\NewHires\resume.txt");

The first two parameters combined make the full path of the source file. The third parameter can be the full path or relative path where the file should be saved. Optionally you can provide the fourth parameter where the specific folder is there in the environment variables. Ex: TMP environment variable can be used.

Copying file from App Server to Storage

This is the reverse of the other. If you want to copy a file from the application server file location to file storage such as ftp or db server, then you can use the function PutAttachment().

PutAttachment(URLDestination, DirAndSysFileName, DirAndLocalFileName[, LocalDirEnvVar[, PreserveCase[, AllowLargeChunks]]])


&retcode = PutAttachment(&FTPINFO, &TARGETFILENAME, "resume.doc");

Copying full files from one location to another

If you have some specific requirement such as copying entire files from one location to another such as after processing a process all the output files needs to be copied to another storage location, then peoplesoft has delivered a function called CopyAttachments().


CopyAttachments(URLSource, URLDestination [, FileRefRecords [, PreserveCase[, AllowLargeChunks]]])

&retcode = CopyAttachments(URL.UrlID, ftp://user:passwd@ftpaddress/");

The first parameter should pass the path for the source location and the second parameter should be path to where all the files should be copied.

Opening a file and viewing it from the browser

You might have attached the files to an application component and sometimes encounter a situation where this file should be opened and displayed from the browser. For example you might have uploaded the resume using AddAttachment function. Now when the recruiter open the profile he will see the attachment link and want to open the resume file. For such scenarios we can use ViewAttachment() function.

ViewAttachment(URLSource, DirAndSysFileName, UserFileName [, NewWindow[, PreserveCase]])

Checking if a file path and filename is correct

Before opening or acting on a file it is necessary to find out that the file name and path are correct. Otherwise the system will throw error during run time if the path or filename is incorrect. To check this PeopleSoft has delivered a function called FileExists().

FileExists(filename [, pathtype])

If FileExists("c:\work\item.txt", %FilePath_Absolute) Then
   &MYFILE = GetFile("c:\work\item.txt", "A");
   /* Process the file */

First parameter will be filename with full path or with relative path. Second parameter will specify if you have specified full path or relative path in the first parameter.

Deleting a file from the storage location

This is also a frequent scenario where you might want to delete a file after temporary processing. Sometimes you might want to delete existing attachment and add a new one. For all these purposes peoplesoft has delivered a built in function called DeleteAttachment(). Before using this function, you might want to check if the file exists using the function mentioned above.

DeleteAttachment(URLSource, DirAndSysFileName[, PreserveCase])

&retcode = DeleteAttachment(URL.BKFTP, ATTACHSYSFILENAME);

There are even other functions to deal with files and attachments. What I have provided above is the basic scenarios which you come across frequently. For more functions, you may refer people books.

For getting a real example of how to use these functions, you can take a look at the peoplecode delivered by peoplesoft under the work record field events in the record FILE_ATTACH_WRK.

For details on creating db record as attachment storage destination, check out the post .


  1. Hi,
    How can you print a file attachment via a App Engine or SQR process. I have a requirement to print a Voucher and the related attachments.


    1. Jay,
      Did you ever figure this out? I have a similar requirement.

  2. viewattachment function by default opens the file in a new browser window. if we pass a value of false, it opens on the same window. But When we try opening the PDF file on the same window ( when value of false is passed to the function) and we are opening the file on the secondary page, secondary page controls are hidden. Close button for the window does not work. is there a way out?

    1. I am afraid that you have to open the file from the secondary modal in a new window rather than on the modal itself. If you are permitted to go a little bit away from Tools Options, you could very well insert an iframe using the HTML element inside the secondary page. Then the content of the attachment can be displayed within the iframe which keeps the modal frame uninterrupted.

      By the way, you could contact Oracle support to see if this is a bug in People Tools and if so if there is already a fix available for it.

  3. Hi, hope someone can help me on this..

    I want to transfer a file from our linux server to the 3rd party Server, using SFTP. But I want this to be done using PIA configuration changes. I have heard that there is a way to do so in the latest peoplesoft release but not sure about how to achieve this. Please help.

    1. Hi Vivek,

      You can go to URL Maintainence page in PeopleSoft to define your SFTP link, user id , password etc.

  4. How can I move a file from FTP one folder to FTP another Folder? CopyAttachments, Copy file but don't delete from source folder.

    1. Hi Navya,

      You can use CopyAttachments for your requirement.


  5. This comment has been removed by the author.

  6. Hi
    I hope you can help me.
    As we know, we can attach files in AP Voucher. Ours is configured to be stored in Database.
    Client raised an issue as when the voucher has been posted, the attached files can still be deleted. Client wanted to ensure that the files won't be deleted and to at least have a back up if ever it was deleted online.
    How can we get the file from database and it is possible to create a back up of the files?


Note: only a member of this blog may post a comment.