Blog pro de Jean-Baptiste HEREN

Notes d'un consultant freelance en informatique

Aller au contenu | Aller au menu | Aller à la recherche

Peoplecode File attachment

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).
This can be done by adding the standard FILE_ATTACH_SBR subrecord.

Then add three buttons to you page :
  • ADD : usually ATTACHADD field
  • VIEW : usually ATTACHVIEW field
  • DELETE: usually ATTACHDELETE field
You can use the standard work record FILE_ATTACH_WRK or just create one with your own fields, like in this example (more flexible).

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();



Article modifié le vendredi 13 novembre 2009, 15:54

Jean-Baptiste HEREN

Auteur: Jean-Baptiste HEREN

Restez au courant de l'actualité et abonnez-vous au Flux RSS de cette catégorie

Les commentaires sont fermés


aucune annexe



Voir aussi

01-_Application_Engine_Process_Definition.png

Trace Application Engine SQL and Peoplecode

Application Engine Trace can be activated by Changing the process Definition. Go in Process Sheduler>process Definition Select the process you want to follow, Go on override tab and add the...

Lire la suite

Finding one component location in the peoplesoft portal

Just replace the 'MY_COMPONENT_GBL' parameter in the following sql script. This works for MS SQl Server. You can add more levels by adding Outer Joins. [SQL] /* Where is my component in the portal */...

Lire la suite