Peoplecode File attachment
Posted on Friday 13 November 2009, 22:47 - Peoplesoft - Permalink Tweet
- Article
- |
- Comments(0)
- |
- Attachments(0)
Peoplesoft allows File attachment from the web client. Here is a little HowTo.
// Peoplesoft permet assez facilement d'utiliser la fonction classique des interfaces web visant à "uploader" un fichier. Voici un aperçu de la méthode.
1- Add Needed Special Fields to your applications's record
First You will have to add two fields containing Filename to you current application's record.Usually you add it to the primary record (aka MY_SCREEN_RECORD in following peoplecode) :
- ATTACHSYSFILENAME (The system file name.)
- ATTACHUSERFILE (The user file name).
Then add three buttons to you page :
- ADD : usually ATTACHADD field
- VIEW : usually ATTACHVIEW field
- DELETE: usually ATTACHDELETE field
2- (Optional) Create record to save File Informations & Data
If you want to use the database to store the file data, you will have to create a record containing this data.This record must have the following Structure :
for example : MY_RECORD_STK
To achieve this, you can use thr standard subrecord FILE_ATTACH_SBR.
3- Add needed peoplecode & associate it with buttons
Here are peoplecodes examples, to be placed on Fieldchange Events, for the three different actions Add, view and remove buttons.- Add Attachment
/*******************************************************************************/
/* Declarations */
Local string &URLDestination, &DirAndFilename, &FileType, &UserFile;
Local number &MaxSize;
/* Affectations */
/* here we set file destination - we can use a record but it is quite better to use an ftp server if possible ftp://ftp.my.address/my_folder */
&URLDestination = "record://MY_RECORD_STK";
&SUBDIRECTORY = "";
&DirAndFilename = "";
&FileType = "";
&UserFile = "";
&MaxSize = 0; /* no limit */
/* Check mandatory Field (file attahment decription) */
If None(MY_SCREEN_RECORD.DESCR254) Then
MessageBox(0, "", 0, 0, "Fields are mandatory ");
Return;
End-If;
/* Use reference IDs as filename, just for unicity */
&ATTACHUSERFILE = MY_SCREEN_RECORD.MY_UNIQUE_ID.Value;
/* reemove special characters */
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, " ", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, ";", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "+", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "%", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "&", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "'", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "!", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "@", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "#", "_");
&ATTACHUSERFILE = Substitute(&ATTACHUSERFILE, "$", "_");
/* Attaching file */
&return = AddAttachment(&URLDestination, &ATTACHUSERFILE, &FileType, &ATTACHSYSFILE, &MaxSize);
If &return = %Attachment_Success /* 0 */ Then
Record.MY_SCREEN_RECORD.FLAG.Value = "Y";
Record.MY_SCREEN_RECORD.ATTACHSYSFILENAME.Value = &ATTACHUSERFILE | &ATTACHSYSFILE;
DoSaveNow();
Else
MY_SCREEN_RECORD.FLAG.Value = "N";
Evaluate &return
When = 7 /* %Attachment_DestSystNotFound */
MessageBox(0, "", 0, 0, "Cannot locate destination system '" | &URLDestination | "'. (Return code " | &return | " )");
Break;
When = 8 /* %Attachment_DestSystFailedLogin */
MessageBox(0, "", 0, 0, "Unable to login to destination system for ftp. (Return code " | &return | " )");
Break;
When-Other
MessageBox(0, "", 0, 0, "Attachment Failed : Error " | &return);
End-Evaluate;
End-If;
- View attachment
/*******************************************************************************/
Local string &URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE;
&URL_ID = "record://MY_RECORD_STK";
&ATTACHSYSFILENAME = Record.MY_SCREEN_RECORD.ATTACHSYSFILENAME.Value;
&ATTACHUSERFILE = Record.MY_SCREEN_RECORD.ATTACHSYSFILENAME.Value;
&MESSAGE_LVL = 1;
&RETCODE = ViewAttachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE);
/* Error Messages */
If (&RETCODE = %Attachment_Cancelled) Then
MessageBox(0, MsgGetText(137, 1, "File Attachment Status"), 137, 3, "AddAttachment cancelled");
End-If;
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;
- Delete attachment
/*******************************************************************************/
Declare Function delete_attachment PeopleCode FILE_ATTACH_WRK.ATTACHDELETE FieldChange;
Function my_delete_attachment() Returns integer
Local string &URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE;
&URL_ID = "record://MY_RECORD_STK";
&ATTACHSYSFILENAME = Record.MY_SCREEN_RECORD.ATTACHSYSFILENAME.Value;
&ATTACHUSERFILE = Record.MY_SCREEN_RECORD.ATTACHSYSFILENAME.Value;
&MESSAGE_LVL = 1;
delete_attachment(&URL_ID, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &MESSAGE_LVL, &RETCODE);
If &RETCODE = 0 Then
MY_SCREEN_RECORD.FLAG.Value = "N";
MY_SCREEN_RECORD.ATTACHSYSFILENAME = "";
End-If;
Return &RETCODE;
End-Function;
/* Main */
&return = my_delete_attachment();
DoSaveNow();