DetachAttachment function
Syntax
DetachAttachment(URLSource, DirAndSysFileName, UserFileName [,PreserveCase])
Description
Use the DetachAttachment function to download a file from its source storage location and save it locally on the end-user machine. The file is sent to the browser with appropriate HTTP headers to cause the browser to display a save dialog box to the user.
The end user can specify any file name to save the file.
Additional information that is important to the use of DetachAttachment can be found in the PeopleTools: PeopleCode Developer's Guide:
-
PeopleTools supports multiple types of storage locations.
See PeopleCode Developer’s Guide: Understanding File Attachment Storage Locations.
-
The PeopleCode file attachment functions do not provide text file conversions when files are attached or viewed.
See PeopleCode Developer’s Guide: Considerations When Attaching Text Files.
-
Because DetachAttachment is interactive, it is known as a “think-time” function, and is restricted from use in certain PeopleCode events.
See PeopleCode Developer’s Guide: Restrictions on Invoking Functions in Certain PeopleCode Events.
-
You can restrict the file types that can be uploaded to or downloaded from your PeopleSoft system.
See PeopleCode Developer’s Guide: Restricting the File Types That Can Be Uploaded or Downloaded.
Parameters
| Parameter | Description |
|---|---|
|
URLSource |
A reference to a URL. This can be either a URL identifier the form URL.URL_ID, or a string. Note: When the URLSource parameter is specified as a string value, forward slashes (/) are required. Backward slashes (\) are not supported for a string value. See PeopleCode Developer’s Guide: Understanding URL Strings Versus URL Objects. |
|
DirAndSysFileName |
The relative path and file name of the file on the file server. This is appended to URLSource to make up the full URL where the file is transferred from. This parameter takes a string value. Note: Because the DirAndSysFileName parameter is appended to the URL, it also requires forward slashes (“/”). Backward slashes (“\”) are not supported for this parameter. |
|
UserFileName |
The default file name provided by the Detach dialog. Note: The file name for the user-selected file cannot be greater than 64 characters. |
|
PreserveCase |
Specify a Boolean value to indicate whether when searching for the file specified by the DirAndSysFileName parameter, its file name extension is preserved or not; True, preserve the case of the file name extension, False, convert the file name extension to all lowercase letters. The default value is False. Warning! If you use the PreserveCase parameter, it is important that you use it in a consistent manner with all the relevant file-processing functions or you may encounter unexpected file-not-found errors. |
Returns
You can check for either an integer or a constant value:
| Numeric Value | Constant Value | Description |
|---|---|---|
|
0 |
%Attachment_Success |
File was transferred successfully. Important: If file type restrictions are changed so that access to a previously uploaded file is now blocked, a call to DetachAttachment will return %Attachment_Success, even though the file and its contents are not downloaded. |
|
1 |
%Attachment_Failed |
File transfer failed due to unspecified error. The following are some possible situations where %Attachment_Failed could be returned:
|
|
2 |
%Attachment_Cancelled |
File transfer didn't complete because the operation was canceled by the end user. |
|
3 |
%Attachment_FileTransferFailed |
File transfer failed due to unspecified error during FTP attempt. The following are some possible situations where %Attachment_FileTransferFailed could be returned:
|
|
7 |
%Attachment_DestSystNotFound |
Cannot locate destination system for FTP. The following are some possible situations where %Attachment_DestSystNotFound could be returned:
|
|
8 |
%Attachment_DestSysFailedLogin |
Unable to login to destination system for FTP. The following are some possible situations where %Attachment_DestSysFailedLogin could be returned:
|
|
9 |
%Attachment_FileNotFound |
Cannot locate file. The following are some possible situations where %Attachment_FileNotFound could be returned:
|
Example
&retcode = DetachAttachment(URL.MYFTP, ATTACHSYSFILENAME, ATTACHUSERFILE);
An example of the DetachAttachment function is provided in the demonstration application delivered in the FILE_ATTACH_WRK derived/work record. This demonstration application is shown on the PeopleTools Test Utilities page.
See PeopleCode Developer’s Guide: Using the PeopleTools Test Utilities Page.
Problems Downloading Files
If you need to use the SetLanguage built-in function to change languages, invoke SetLanguage prior to invoking ViewAttachment or DetachAttachment. You must place the call to SetLanguage in a different PeopleCode program and event from the PeopleCode program and event that invokes ViewAttachment or DetachAttachment.