How to use GetAttachment and PutAttachment PeopleSoft Builtin Functions

A while ago I had a requirement to transfer attachments from a source FTP server location and store it into a database record. To do that you have to use GetAttachment and PutAttachment PeopleCode functions. Basically GetAttachment PeopleCode function can be used to download the attachment from its source storage location (say FTP or database record) to the application server and then you can use PutAttachment PeopleCode function to upload the attachment from the app server file system to the specified storage location (e.g. to a database record).

The GetAttachment and PutAttachment the function Parameters are as follows;

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

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

The first parameter for the GetAttachment function is URLSource. This indicates the source location of the file. This can be implemented as a URL object with the form of URL.URL_ID. URL object is an identifier of the storage location including the protocol to be used (e.g. ftp) and the address of the storage location. URL objects can be created and maintained using URL maintenance page; PeopleTools > Adminstration > Utilities > URLs.
Length of the full URL is limited to 254 characters. For the file attachment functionality, in specifying the URL for the FTP server, the FTP server's machine name can be more than 30 characters, but the length of the full URL is limited to 120 characters.
Following protocol types can be used for the URLID
  • FTP
  • FTPS (FTP over SSL)
  • SFTP
  • HTTP
For plain FTP URL object can be referenced in one of the following formats;
  • ftp://<username>:<password>@<machinename> where the FTP user and FTP password are provided in clear text, but the URL information comes from the URL object. 
  • ftp://<username>@<machinename> where the FTP user is provided in clear text, but the FTP password and the URL information comes from the URL object.
    ftp://<machinename> where all the required information comes from the URL.

The first parameter for the PutAttachment function is URLDestination. This indicates the destination location of the file (in this case database record). An URL object can be create to indicate the database record you want to store the attachments.

Things to consider when storing attachments in the database

If the files are stored in a database table, PeopleSoft divided the files in to chunks before storing in to the database table. The chunk size is governed by the value of the Maximum Attachment Chunk Size field on the PeopleTools Options page (PeopleTools > Utilities > Administration > PeopleTools Options). 
As an example you can use this PeopleCode to Get and Put attachments as follows;

Local number &retCodeGet, &retCodePut;
   &retCodeGet = GetAttachment(URL.TEST_URL, "test_123.pdf", "Example_test.pdf");
   If &retCodeGet = %Attachment_Success Then
      &FileName = "Example_test.pdf";
      &retCodePut = PutAttachment(URL.ATTACHMENT_DB_REC, &UniqueName, &FileName);
      If &retCodePut = %Attachment_Success Then
         WinMessage("Put Att Success: " | &retCodePut);
         WinMessage("Error occurred in Put Att: " | &retCodePut);
      WinMessage("Error occurred in Get Att: " | &retCodeGet);



    Blogger Comment
    Facebook Comment


Post a Comment