Anda di halaman 1dari 19

File Attachment in Peoplesoft

File attachments are supported by using PeopleCode built-in functions that implement the
transfer of a file to or from a storage location. Using the PeopleCode functions, files
can be transferred back and forth from the end user machine to the storage. PeopleTools
supports three types of storage locations: database tables, FTP sites, and HTTP
repositories.

This blog is created for holding my quick reference notes. At the same time these could be
helpful for visitors if they want to get the file attachment functionality working real
fast without going through too much detailed documentation. Once you have an example file
attachment working in your development environment, you can go back to peoplebooks and
other documentation for understanding additional related topics and experiment with your
creative ideas. I believe, after getting the example working first, the related
peoplebooks were understood faster too.

The example has been created and tested on the following software environment.
Peoplesoft Application: FSCM 9.2.005
Peoplesoft Peopletools: 8.53.09
Peoplesoft Virtual Machine Image id: FSCMDB-8309-PI005
Database: Oracle 11.2.0.3

Let us begin with example.

We have a project AJ_ATTACHMENT which contains the objects used, as shown below.

The objects with names starting with AJ are new objects. Others are delivered. Let us
create objects.

Records.
It is a view with the SQL
SELECT a.business_unit , a.voucher_id FROM ps_voucher a

With following Peoplecode.

Business_UNIT.FieldDefault
Component number &SEQ_NUM_NUM;
SQLExec("SELECT MAX(SEQ_NUM) FROM RECORD.AJ_VCHR_ATTACH WHERE AJ_VCHR_ATTACH.BUSINESS_UNIT
= :1 AND AJ_VCHR_ATTACH.VOUCHER_ID = :2", &SEQ_NUM_NUM, AJ_VCHR_SRCH_VW.BUSINESS_UNIT,
AJ_VCHR_SRCH_VW.VOUCHER_ID);

Business_UNIT.RowInit
Component number &SEQ_NUM_NUM;
Local number &Rs_Count, &i;
Local Rowset &Rs;
&Rs = GetLevel0()(1).GetRowset(Scroll.AJ_VCHR_ATTACH);
&Rs_Count = &Rs.ActiveRowCount;
&SEQ_NUM_NUM = 0;
For &i = &Rs_Count To 1 Step - 1
If (&Rs(&i).AJ_VCHR_ATTACH.SEQ_NUM.Value) > &SEQ_NUM_NUM Then
&SEQ_NUM_NUM = &Rs(&i).AJ_VCHR_ATTACH.SEQ_NUM.Value;
End-If;
End-For;

Peoplecode
SEQ_NUM.FieldDefault
Component number &SEQ_NUM_NUM;
&SEQ_NUM_NUM = &SEQ_NUM_NUM + 1;
If AJ_VCHR_ATTACH.SEQ_NUM = 0 Or
None(AJ_VCHR_ATTACH.SEQ_NUM) Then
AJ_VCHR_ATTACH.SEQ_NUM = 1;
&SEQ_NUM_NUM = 1;
End-If;

SEQ_NUM.RowDelete
Declare Function delete_attachment PeopleCode AJ_ATTACH_WRK.ATTACHDELETE FieldChange;
Declare Function display_attachment_buttons PeopleCode AJ_ATTACH_WRK.ATTACHADD RowInit;
Local number &Ret;
Local string &URL_ID;
&Ret = MessageBox(%MsgStyle_YesNo, "", 0, 0, "Are you sure you would like to delete the
attachment?");
If &Ret = %MsgResult_Yes Then
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the correct database record where your file attachment */
/* will be stored */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&URL_ID = "URL.AJ_VCHR_ATTACH";
If All(AJ_VCHR_ATTACH. ATTACHUSERFILE) Then
delete_attachment(@&URL_ID, AJ_VCHR_ATTACH.ATTACHSYSFILENAME,
AJ_VCHR_ATTACH.ATTACHUSERFILE, 2, &RETCODE);

If &RETCODE = %Attachment_Success Then


display_attachment_buttons("");
AJ_VCHR_ATTACH.ATTACHSYSFILENAME = "";
AJ_VCHR_ATTACH.ATTACHUSERFILE = "";
End-If;
End-If;
End-If;

SEQ_NUM.RowInit
Declare Function display_attachment_buttons PeopleCode AJ_ATTACH_WRK.ATTACHADD RowInit;
display_attachment_buttons(AJ_VCHR_ATTACH.ATTACHUSERFILE);

SEQ_NUM.RowInsert
Component number &SEQ_NUM_NUM;
&SEQ_NUM_NUM = &SEQ_NUM_NUM + 1;
AJ_VCHR_ATTACH.SEQ_NUM = &SEQ_NUM_NUM;

This record has a sub-record and it cannot have any other field.

This record is cloned from FILE_ATTACH_WRK, including peoplecode ( 5 field/events).


In the copied peoplecode, change the record from FILE_ATTACH_WRK to AJ_ATTACH_WRK. The
peoplecode will look like the following.

ATTACHADD.FieldChange
Declare Function IsLegalAttachmentType PeopleCode AJ_ATTACH_WRK.ATTACHUTIL FieldChange;
Function add_attachment(&URL_ID, &FILEEXTENSION, &SUBDIRECTORY, &FILESIZE, &PREPEND,
&RECNAME, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &MESSAGE_LVL, &RETCODE);
/*
&URL is your File Server's FTP URL_ID!
&FILEEXTENSION indicates an extension, such as ".txt",".jpg",".html",".doc", or ".exe"
or "" (default) for any file (used only in Windows)
&SUBDIRECTORY indicates a subdirectory on the file server, prepend it to
ATTACHSYSFILENAME e.g. "HR/ABSENCEHIST/"
&FILESIZE is the max file size in kbyte. Use 0 to indicate no limit, or don't specify
the paramter.
&PREPEND is a True/False parameter. This is used in conjunction with
&ATTACHSYSFILENAME.
&PREPEND Input &ATTACHSYSFILENAME Output &ATTACHSYSFILENAME
----------- ------------------------
-------------------------------------------------
True Blank Keys of records prepended to &ATTACHUSERFILE
True Not blank &ATTACHSYSFILENAME prepended to &ATTACHUSERFILE
False Not Blank &ATTACHSYSFILENAME prepended to &ATTACHUSERFILE
False Blank &ATTACHUSERFILE
NOTE: Case 2 and 3 result in same behavior. In future, we will have case 3 return
without &ATTACHUSERFILE.
&RECNAME is the record name that has the attachments. Used in the prepend option
above.
&ATTACHSYSFILENAME is the filename on the file server.
&ATTACHUSERFILE is the filename the user uses.
&MESSAGE_LVL: 0 - suppress all messages including errors
1 - display all messages
2 - suppress only successful message but will display error messages.
&RETCODE is the return code from the attachment call. You can evaluate &retcode and
manipulate the attachment buttons as needed in your application. For example, you may
want to call the function display_attachment_buttons(&ATTACHUSERFILE) in ATTACHADD RowInit
if addattachment was successful.
*/
&ORIGSYSFILENAME = &ATTACHSYSFILENAME;
If &PREPEND And None(&ORIGSYSFILENAME) Then
&uniquefilename = "";
&REC = GetRecord(@&RECNAME);
For &I = 1 To &REC.FieldCount
&Fld = &REC.getfield(&I);
If (&Fld.IsKey = True) Then
If (&Fld.value = "" And
&Fld.IsRequired = True) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 28,
"Please attach the file after filling out the required fields on this page.");
Return;
Else
&uniquefilename = &uniquefilename | &Fld.value;
End-If;
End-If;
End-For;
&temp = Substitute(&uniquefilename, " ", ""); /* delete spaces */
&ATTACHSYSFILENAME = Left(&uniquefilename, 64); /* make uniq part a max of 64 chars
*/
End-If;
&ATTACHSYSFILENAME = &SUBDIRECTORY | &ATTACHSYSFILENAME;
If Exact(Left(&URL_ID, 4), "URL.") Then
&RETCODE = AddAttachment(@(&URL_ID), &ATTACHSYSFILENAME, &FILEEXTENSION,
&ATTACHUSERFILE, &FILESIZE);
Else
&RETCODE = AddAttachment(&URL_ID, &ATTACHSYSFILENAME, &FILEEXTENSION,
&ATTACHUSERFILE, &FILESIZE);
End-If;
/* The actual name on the ftp file server is the following */
If &PREPEND Or All(&ORIGSYSFILENAME) Then
&ATTACHSYSFILENAME = &ATTACHSYSFILENAME | &ATTACHUSERFILE;
Else
&ATTACHSYSFILENAME = &SUBDIRECTORY | &ATTACHUSERFILE;
End-If;
&temp = Substitute(&ATTACHSYSFILENAME, " ", ""); /* delete spaces */
&ATTACHSYSFILENAME = &temp;
If (&RETCODE = %Attachment_Cancelled) Then
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 3,
"AddAttachment cancelled");
End-If;
End-If;
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
If (&RETCODE = %Attachment_Failed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 2,
"AddAttachment failed");
End-If;
If (&RETCODE = %Attachment_FileTransferFailed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 4,
"AddAttachment failed: File Transfer did not succeed");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceAppServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 5,
"AddAttachment failed: No disk space on the app server");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceWebServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 6,
"AddAttachment failed: No disk space on the web server");
End-If;
If (&RETCODE = %Attachment_FileExceedsMaxSize) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 7,
"AddAttachment failed: File exceeds the max size");
End-If;
If (&RETCODE = %Attachment_DestSystNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 8,
"AddAttachment failed: Cannot locate destination system for ftp");
End-If;
If (&RETCODE = %Attachment_DestSysFailedLogin) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 9,
"AddAttachment failed: Unable to login into destination system for ftp");
End-If;
If (&RETCODE = %Attachment_FileNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 29, "The file
was not found so the operation could not be completed.");
End-If;
/* Error Message for Invalid file or No file name */
If (&RETCODE = %Attachment_NoFileName) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 38,
"AddAttachment failed: No File Name Specified.");
End-If;
/* Error Message for file name being too long */
If (&RETCODE = %Attachment_FileNameTooLong) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 55,
"AddAttachment failed: File name too long.");
End-If;
If (&RETCODE = %Attachment_ViolationFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 51,
"AddAttachment failed: File violation detected.");
End-If;
If (&RETCODE = %Attachment_VirusConfigError) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 52,
"AddAttachment failed: Virus Scan Engine configuration error.");
End-If;
If (&RETCODE = %Attachment_VirusConnectError) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 53,
"AddAttachment failed: Virus Scan Engine Connection error.");
End-If;
If (&RETCODE = %Attachment_VirusScanError) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 54,
"AddAttachment failed: Virus Scan Engine error.");
End-If;
End-If;
If (&RETCODE = %Attachment_Success) Then
If ( Not (IsLegalAttachmentType(&ATTACHUSERFILE))) Then
/*Illegal file extension. Delete the uploaded fle and return error */
If Exact(Left(&URL_ID, 4), "URL.") Then
&RETCODE = DeleteAttachment(@(&URL_ID), &ATTACHSYSFILENAME);
Else
&RETCODE = DeleteAttachment(&URL_ID, &ATTACHSYSFILENAME);
End-If;
&SUBDIRECTORY = "";
&ATTACHUSERFILE = "";
&ATTACHSYSFILENAME = "";
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 0, 0,
"AddAttachment failed: Unauthorized file extension");
End-If;
&RETCODE = %Attachment_Failed;
Else
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 27,
"AddAttachment succeeded");
End-If;
End-If;
Else
&ATTACHUSERFILE = "";
&ATTACHSYSFILENAME = "";
End-If;
End-Function;

ATTACHADD.RowInit
Function display_attachment_buttons(&ATTACHUSERFILE);
If (&ATTACHUSERFILE <> "") Then
Hide(AJ_ATTACH_WRK.ATTACHADD);
UnHide(AJ_ATTACH_WRK.ATTACHVIEW);
UnHide(AJ_ATTACH_WRK.ATTACHDELETE);
UnHide(AJ_ATTACH_WRK.ATTACHDET);
Else
UnHide(AJ_ATTACH_WRK.ATTACHADD);
Hide(AJ_ATTACH_WRK.ATTACHVIEW);
Hide(AJ_ATTACH_WRK.ATTACHDELETE);
Hide(AJ_ATTACH_WRK.ATTACHDET);
End-If;
End-Function;

ATTACHDET.FieldChange
Declare Function IsLegalAttachmentType PeopleCode AJ_ATTACH_WRK.ATTACHUTIL FieldChange;
Function detach_attachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &MESSAGE_LVL,
&RETCODE)
/* &MESSAGE_LVL: 0 - suppress all messages including errors
1 - display all messages
2 - suppress only successful message but will display error messages.
&RETCODE is the return code from the attachment call. You can evaluate &retcode and
manipulate the attachment buttons as needed in your application. For example, you may
want to call the function display_attachment_buttons(&ATTACHUSERFILE) in ATTACHADD RowInit
if addattachment was successful.
*/
If (IsLegalAttachmentType(&ATTACHSYSFILENAME)) Then
If Exact(Left(&URL_ID, 4), "URL.") Then
&RETCODE = DetachAttachment(@(&URL_ID), &ATTACHSYSFILENAME, &ATTACHUSERFILE);
Else
&RETCODE = DetachAttachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE);
End-If;
If (&RETCODE = %Attachment_Cancelled) Then
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 3,
"AddAttachment cancelled");
End-If;
End-If;
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
If (&RETCODE = %Attachment_Failed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 19,
"DetachAttachment failed");
End-If;
If (&RETCODE = %Attachment_FileTransferFailed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 21,
"DetachAttach ment failed: File Transfer did not succeed");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceAppServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 22,
"DetachAttach ment failed: No disk space on the app server");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceWebServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 23,
"DetachAttach ment failed: No disk space on the web server");
End-If;
If (&RETCODE = %Attachment_FileExceedsMaxSize) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 24,
"DetachAttach ment failed: File exceeds the max size");
End-If;
If (&RETCODE = %Attachment_DestSystNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 25,
"DetachAttach ment failed: Cannot locate destination system for ftp");
End-If;
If (&RETCODE = %Attachment_DestSysFailedLogin) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 26,
"DetachAttach ment failed: Unable to login into destination system for ftp");
End-If;
End-If;
Else
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 0, 0,
"DetachAttachment failed: Unauthorized file extension");
End-If;
End-If;
End-Function;

ATTACHDELETE.FieldChange
Function delete_attachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &MESSAGE_LVL,
&RETCODE)
/* &MESSAGE_LVL: 0 - suppress all messages including errors
1 - display all messages
2 - suppress only successful message but will display error messages.
&RETCODE is the return code from the attachment call. You can evaluate &retcode and
manipulate the attachment buttons as needed in your application. For example, you may
want to call the function display_attachment_buttons(&ATTACHUSERFILE) in ATTACHADD RowInit
if addattachment was successful.
*/
If Exact(Left(&URL_ID, 4), "URL.") Then
&RETCODE = DeleteAttachment(@(&URL_ID), &ATTACHSYSFILENAME);
Else
&RETCODE = DeleteAttachment(&URL_ID, &ATTACHSYSFILENAME);
End-If;
If (&RETCODE = %Attachment_Success) Then
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 10,
"DeleteAttachment succeeded");
End-If;
&ATTACHUSERFILE = "";
&ATTACHSYSFILENAME = "";
End-If;
If (&RETCODE = %Attachment_Cancelled) Then
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 3,
"AddAttachment cancelled");
End-If;
End-If;
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
If (&RETCODE = %Attachment_Failed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 11,
"DeleteAttachment failed");
End-If;
If (&RETCODE = %Attachment_FileTransferFailed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 13,
"DeleteAttachment failed: File Transfer did not succeed");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceAppServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 14,
"DeleteAttachment failed: No disk space on the app server");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceWebServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 15,
"DeleteAttachment failed: No disk space on the web server");
End-If;
If (&RETCODE = %Attachment_FileExceedsMaxSize) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 16,
"DeleteAttachment failed: File exceeds the max size");
End-If;
If (&RETCODE = %Attachment_DestSystNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 17,
"DeleteAttachment failed: Cannot locate destination system for ftp");
End-If;
If (&RETCODE = %Attachment_DestSysFailedLogin) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 18,
"DeleteAttachment failed: Unable to login into destination system for ftp");
End-If;
End-If;
End-Function;

ATTACHVIEW.FieldChange
Declare Function IsLegalAttachmentType PeopleCode AJ_ATTACH_WRK.ATTACHUTIL FieldChange;
Function view_attachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &MESSAGE_LVL,
&RETCODE)
/* &MESSAGE_LVL: 0 - suppress all messages including errors
1 - display all messages
2 - suppress only successful message but will display error messages.
&RETCODE is the return code from the attachment call. You can evaluate &retcode and
manipulate the attachment buttons as needed in your application. For example, you may
want to call the function display_attachment_buttons(&ATTACHUSERFILE) in ATTACHADD RowInit
if addattachment was successful.
IsLegalAttachmentType(&ATTACHSYSFILENAME) condition as of now, will prevent files with
a .JSP extension
from being viewed. Additional extensions may be added to prevent the viewing of
additional file types.
Please see IsLegalAttachmentType() on FILE_ATTACH_WRK.ATTACHUTIL FieldChange to add
additional extensions.
*/
/* ICE:1187171004 */
/*If (Upper(Right(&ATTACHSYSFILENAME, 4)) <> ".JSP") Then*/
If (IsLegalAttachmentType(&ATTACHSYSFILENAME)) Then
If Exact(Left(&URL_ID, 4), "URL.") Then
&RETCODE = ViewAttachment(@(&URL_ID), &ATTACHSYSFILENAME, &ATTACHUSERFILE);
Else
&RETCODE = ViewAttachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE);
End-If;
If (&RETCODE = %Attachment_Cancelled) Then
If &MESSAGE_LVL = 1 Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 3,
"AddAttachment cancelled");
End-If;
End-If;
If &MESSAGE_LVL = 1 Or &MESSAGE_LVL = 2 Then
If (&RETCODE = %Attachment_Failed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 19,
"ViewAttachment failed");
End-If;
If (&RETCODE = %Attachment_FileTransferFailed) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 21,
"ViewAttachment failed: File Transfer did not succeed");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceAppServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 22,
"ViewAttachment failed: No disk space on the app server");
End-If;
/* following error messsage only in iclient mode */
If (&RETCODE = %Attachment_NoDiskSpaceWebServ) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 23,
"ViewAttachment failed: No disk space on the web server");
End-If;
If (&RETCODE = %Attachment_FileExceedsMaxSize) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 24,
"ViewAttachment failed: File exceeds the max size");
End-If;
If (&RETCODE = %Attachment_DestSystNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 25,
"ViewAttachment failed: Cannot locate destination system for ftp");
End-If;
If (&RETCODE = %Attachment_DestSysFailedLogin) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 26,
"ViewAttachment failed: Unable to login into destination system for ftp");
End-If;
If (&RETCODE = %Attachment_FileNotFound) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 29,
"ViewAttachment failed: No attachment found in ftp");
End-If;
End-If;
Else
/* File extension check failed - reject viewing */
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 0, 0, "ViewAttachment
failed: Unauthorized file extension");
End-If; /* End file extension check */
End-Function;

ATTACHUTIL.FieldChange
/* ICE: 1187171004 */
/* Determine if file name has a file type which is legal for attachments */
Function IsLegalAttachmentType(&str_AttachFileName As string) Returns boolean;
rem Create array of illegal file types (use uppercase only!);
Local array of string &IllegalTypesArray = CreateArray(".JSP");
rem Clean up the input file name;
Local string &strAttachFileNameUpper = Upper(LTrim(RTrim(&str_AttachFileName)));
rem Assume the file type is legal for now;
Local boolean &IsLegal = True;
rem Search the array to see if the file name has an illegal file type;
Local integer &I;
Local integer &ArrayCnt = &IllegalTypesArray.Len;
For &I = 1 To &ArrayCnt
Local string &str_AttachFileType = Right(&strAttachFileNameUpper,
Len(&IllegalTypesArray [&I]));
If &str_AttachFileType = &IllegalTypesArray [&I] Then
rem The file type is illegal;
&IsLegal = False;
Break;
End-If;
End-For;
rem Return the answer;
Return &IsLegal;
End-Function;

Page
The fields Business_Unit and Voucher_ID are invisible. The fields SEQ_NUM and
ATTACHUSERFILE are display only. The fields ATTACHADD, ATTACHVIEW, and ATTACHDELETE are
pushbuttons.

The Component.
With following peoplecode.

ATTACHADD.FieldChange
Declare Function add_attachment PeopleCode AJ_ATTACH_WRK.ATTACHADD FieldChange;
Declare Function display_attachment_buttons PeopleCode AJ_ATTACH_WRK.ATTACHADD RowInit;
Local number &CurRow, &RETCODE;
Local string &Guid, &URL_ID;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the correct database record where your file attachment */
/* will be stored */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&URL_ID = "URL.AJ_VCHR_ATTACH";
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* In order to make sure the attachmentname is unique */
/* you can add a GUID in front of your File name */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&Guid = UuidGenBase64();
add_attachment(@&URL_ID, "", &Guid, 0, True, "Record.AJ_VCHR_ATTACH",
AJ_VCHR_ATTACH.ATTACHSYSFILENAME, AJ_VCHR_ATTACH.ATTACHUSERFILE, 2, &RETCODE);
If &RETCODE = %Attachment_Success Then
display_attachment_buttons("Success");
DoSaveNow();
End-If;

ATTACHDELETE.FieldChange
Declare Function delete_attachment PeopleCode AJ_ATTACH_WRK.ATTACHDELETE FieldChange;
Declare Function display_attachment_buttons PeopleCode AJ_ATTACH_WRK.ATTACHADD RowInit;
Local number &Ret;
Local string &URL_ID;
&Ret = MessageBox(%MsgStyle_YesNo, "", 0, 0, "Are you sure you would like to delete the
attachment?");
If &Ret = %MsgResult_Yes Then
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the correct database record where your file attachment */
/* will be stored */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&URL_ID = "URL.AJ_VCHR_ATTACH";
delete_attachment(@&URL_ID, AJ_VCHR_ATTACH.ATTACHSYSFILENAME,
AJ_VCHR_ATTACH.ATTACHUSERFILE, 2, &RETCODE);
If &RETCODE = %Attachment_Success Then
display_attachment_buttons("");
DoSaveNow();
End-If;
End-If;

ATTACHVIEW.FieldChange
Declare Function view_attachment PeopleCode AJ_ATTACH_WRK.ATTACHVIEW FieldChange;
Declare Function display_attachment_buttons PeopleCode AJ_ATTACH_WRK.ATTACHADD RowInit;
Local string &URL_ID;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the correct database record where your file attachment */
/* will be stored */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&URL_ID = "URL.AJ_VCHR_ATTACH";
view_attachment(@&URL_ID, AJ_VCHR_ATTACH.ATTACHSYSFILENAME, AJ_VCHR_ATTACH.ATTACHUSERFILE,
2, &RETCODE);
If &RETCODE = %Attachment_Success Then
display_attachment_buttons("Success");
DoSaveNow();
End-If;

Add a new URL definition Online

This may not necessary if the attachments are to be stored in the Database, unless you
plan to change the attachment record later. But for uniformity and for avoiding changes to
peoplecode, you might consider creating a URL definition. If storing on a file server, you
should create a URL definition since server names can change.
Navigate to Main Menu > PeopleTools > Utilities > Administration > URLs.
Add a new URL (i.e. AJ_DEMO_ATTACH) and save.

Note: We will see the difference in URLID for FTP and HTTP, later in the document.

Add component to a menu.

Register the component.

Add security.

Test
Page pulls up:

Press the Add Attachment button. A Dialog box will appear to select the desired file on
the local computer:

Press the Browse button. Using the standard Windows dialog box, select the file you wish
to attach.
Press the Upload button.
The attached file is now displayed in the grid. The View and Delete buttons are visible
now.

Let us see how the data base tables look now.


Note 1: The delivered process has split the file into smaller pieces and stored each
piece as a separate record in the storage table AJ_VCHR_ATTDOCS. When the file is
retrieved using VIEW button, these pieces will be added together by peoplesoft before
presenting the file to you.
Note 2: In the peoplecode, GUID was placed at the beginning of the filename to create the
ATTACHSYSFILENAME to have a unique system file name. This will allow two VOUCHER_ID to
have attachments with the same user filenames but different contents as they will have but
different system filenames. For example voucher 101 can have an attachment invoice.pdf
containing the image of an invoice for voucher 101 while voucher 102 can have an
attachment with the same name invoice.pdf containing the image of an invoice for voucher
102. There will be no conflict as the system file name will be different. I will show you
this part with an example when I add an attachment to Voucher APB02.
We will attach another file to the voucher APB01. Press on the + button. It will create
a new row with Add button.

We will follow the same steps as we did for first attachment.


After that the page will look something like this.

Let us see how the data base tables look now after the second attachment.
Now I will delete all attachments from voucher APB01. After that I will attach a document
named invoice.pdf related to APB01 as first attachment to APB01. Similarly I will attach a
document named invoice.pdf (same name as previous voucher) related to APB02 as first
attachment to APB02.
The Page containing APB01 looks like

The Page containing APB02 looks like

And the database looks like


Notice the voucher_id number is different.

Notice that the file attached to voucher APB01 has 3 rows while the one for APB02 has 5
rows as the file attached to APB02 is bigger than that for APB01.

That covers an example of file attachment in peoplesoft when the attachments are saved in
the database. If the requirement is to save the attachments at FTP or HTTP site instead of
database, the only thing you need to changes is the URL. For example,
if the file attachments are to be saved at an FTP site, the URL definition will look like
if the file attachments are to be saved at an HTTP site, the URL definition will look like

In the FTP and HTTP method, clearly we do not need the record AJ_VCHR_ATTDOCS.

Anda mungkin juga menyukai