2015年4月13日星期一

Using Attachment Functions

Using Attachment Functions
https://psbooks.mycmsc.com/PSOL/hr90_849/eng/psbooks/tpcd/chapter.htm?File=tpcd/htm/tpcd11.htm%23H4015

To use the attachment functions:

Insert the subrecord FILE_ATTACH_SBR into a record used with your page.

Typically, this record is inserted as part of the primary database record.

To store the file in the database, insert the subrecord FILE_ATTDET_SBR into a record used with your page.

This record can be called anything, but it must have the FILE_ATTDET_SBR subrecord included in it, and have no additional fields in it. This is the record that you point to with the URL when specifying storing a file in a database table.

Add buttons to add, delete, and view attachments as needed.

You can either use the FILE_ATTACH_WRK record for the necessary record fields, or you can use your own work fields.

Set up the URL.

If you're using the FTP archive, suppose the system is fileserver.ps.com, the user account is joe, and the password is secret. The full URL is: ftp://joe:secret@fileserver.ps.com/.

You can either create an entry for this URL in the URL Maintenance page, or specify it in your PeopleCode.

If you specify the URL in your PeopleCode, you don't have to hard-code the username and password. You can dereference them using a variable or record field. This enables you to use encryption with the username and password.

If you're copying to a database table, you can either create an entry for this record (URL) in the URL Maintenance page, or specify it in your PeopleCode, as follows:

record://RESUMES_DB
Modify the PeopleCode to support your application.

If you use the supplied PeopleCode programs, you must specify the URL. You may also want to modify the extension of the expected files (the default is "", which is any file, or *.* You may want to indicate ".doc", ".xl", "*.html", "*.exe", and "*.tar".). Read the comments in ATTACHADD FieldChange program for instructions.

To use the FILE_ATTACH_WRK record for buttons, you may want to use component PeopleCode for your application-specific code. This enables you to keep the code in FILE_ATTACH_WRK generic. If you use your own work fields, you can write your own code and call the functions in FILE_ATTACH_WRK as needed.

See URL Maintenance.

Coding Considerations Using the Attachment Functions

All file attachments are performed using PeopleCode built-in functions, such as AddAttachment, ViewAttachment, GetAttachment, and so on. These functions move a file into and out of a file storage system, either the database or a file system. The file system movement is done using the FTP protocol.

Because these functions abstract the storage of the attachments, you can use either database or FTP file systems. The system to be used is determined by the URL passed as the first parameter in the attachment built-in function. The actual value of the URL is maintained on the URL Maintenance page. This means that the you don't know whether users will store attachments in a database or a file system.

The following PeopleCode functions are used with administration work:

DeleteAttachment deletes unwanted attachments.

There is no roll-back ability. For example, suppose a user selects to view an attachment, then cancels before the attachment is displayed. A copy of the attachment may still be in the user's temp directory.

CopyAttachments moves all of the attachments specified from one file storage system (database or FTP) to another (database or FTP).

CleanAttachments is an audit-like script that removes attachments that exist in the database that are not referenced by any record field.

If you only have a few files to copy using CopyAttachments, you may want to use the CopyFiles page (part of the PeopleTools Administration pages). The CleanAttachments function is also available from this page.

To schedule a regular job to clean up orphaned file attachments, you can use the Application Engine program CLEANATT84.

Store all references to attachments using the standard ATTACHSYSFILENAME field. Do not reuse this field to store incomplete or nonstandard versions of the name. For example, you should not store the full URL version of the attachment in this column and then use PeopleCode to parse the URL before invoking attachment commands. While this may work for get or put attachment calls, the Clean Attachments function deletes any file stored in a table that does not have a corresponding reference stored in ATTACHSYSFILENAME.

Copying Files Using the File Attachment Functions

The CopyAttachments function is used for moving a group of attachments from one archive to another, such as when you want to move files from one FTP server to another, or if you want to move all the files in a database record out onto an FTP server. It does not create new system file links.

If you want to create a new file attachment by making a copy of an existing file attachment (both the system file link and the file itself, ) do the following:

Use GetAttachmentto retrieve the file from the repository (either from the FTP server or from a database record) and place it on your application server (or process scheduler system if you are using PeopleSoft Application Engine.)

Use PutAttachment to move the file from the application server (or process scheduler system) and place it into the new archive location.

Save the new system file link that you passed as a parameter to PutAttachment so that you can subsequently use it. This is generally part of the page transaction when you save the record that has the FILE_ATTACH_SBR subrecord in it.

没有评论:

发表评论