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]]]])
Example:
&retcode
= AddAttachment(URL.MYFTP, ATTACHSYSFILENAME, "", ATTACHUSERFILE, 0);
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.
Syntax:
GetAttachment(URLSource,
DirAndSysFileName, DirAndLocalFileName[, LocalDirEnvVar[, PreserveCase]])
Example:
&retcode
= GetAttachment("ftp://anonymous:hobbit1@ftp.ps.com/HRarchive/", ⇒
"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().
Syntax:
PutAttachment(URLDestination,
DirAndSysFileName, DirAndLocalFileName[, LocalDirEnvVar[, PreserveCase[,
AllowLargeChunks]]])
Example:
&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().
Syntax:
CopyAttachments(URLSource,
URLDestination [, FileRefRecords [, PreserveCase[, AllowLargeChunks]]])
Example:
&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.
Syntax:
ViewAttachment(URLSource,
DirAndSysFileName, UserFileName [, NewWindow[, PreserveCase]])
Example:
&retcode
= ViewAttachment(URL.MYFTP, ATTACHSYSFILENAME, ATTACHUSERFILE);
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().
Syntax:
FileExists(filename
[, pathtype])
Example:
If
FileExists("c:\work\item.txt", %FilePath_Absolute) Then
&MYFILE =
GetFile("c:\work\item.txt", "A");
/* Process the file */
&MYFILE.Close();
End-If;
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.
Syntax:
DeleteAttachment(URLSource,
DirAndSysFileName[, PreserveCase])
Example:
&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.