Delete a File Using PeopleCode

Your rating: None Average: 3.4 (5 votes)

It is always a good idea to check for a file if exists before trying to delete it. So the code below will check for that and then will attempt to delete the file if found. The delete is performed using the build-in peoplecode function DeleteAttachment.
The code below also checks for the returned code by the function to verify whether the file has been deleted or not.
&retcode = DeleteAttachment(URL.BKFTP, ATTACHSYSFILENAME);
If (&retcode = %Attachment_Success) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment succeeded”);
UnHide(ATTACHADD);
Hide(ATTACHVIEW);
Hide(ATTACHDELETE);
ATTACHUSERFILE = “”;
ATTACHSYSFILENAME = “”;
End-If;
If (&retcode = %Attachment_Failed) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed”);
End-If;
If (&retcode = %Attachment_Cancelled) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment cancelled”);
End-If;
If (&retcode = %Attachment_FileTransferFailed) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: File Transfer did not succeed”);
End-If;
/* following error message only in PeopleSoft Pure Internet Architecture */
If (&retcode = %Attachment_NoDiskSpaceAppServ) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: No disk space on the app server”);
End-If;
/* following error message only in PeopleSoft Pure Internet Architecture */
If (&retcode = %Attachment_NoDiskSpaceWebServ) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: No disk space on the web server”);
End-If;
If (&retcode = %Attachment_FileExceedsMaxSize) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: File exceeds the max size”);
End-If;
If (&retcode = %Attachment_DestSystNotFound) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: Cannot locate destination system for ftp”);
End-If;
If (&retcode = %Attachment_DestSysFailedLogin) Then
MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: Unable to login into destination system for ftp”);
End-If;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!