Delete a File Using PeopleCode

No votes yet

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!

Comments

Have a question? Please ask it on the forum instead.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
The question below is to prevent automated spam submissions.
7 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.