Home / Educational Content / PeopleSoft / How to Delete A File With PeopleCode

How to Delete A File With PeopleCode

Person holding tablet in front of servers
Cory Flowers, Quest Guest Blogger | Blog content sourced from Ps_App_Development

I had a requirement to create a log file with an application engine based upon a user entering a bad voucher when utilizing the Excel to CI ExcelUploadforVoucher.xlsm. I created an application engine that will validate that the vouchers are correct according to the business rules set forth by the functional business team. Once this log file is created, the file has to be attached to an email and then be sent to both the user and the functional business analyst who is in charge of the voucher build process. Once the file has been attached to the email, it needs to be deleted off the file server. This is how I accomplished the task.

I created a PeopleCode step in my application engine and used this code to remove the file.

Local string &OPRID, &FileName, &DATABASE, &Path;
Local File &file;

/* Set the Operator Id from the State Record in the Application Engine*/;

&OPRID = VCHR_EDT_AET.OPRID2;

&FileName = &OPRID | “_Bad_Vouchers.txt”;

/* Set the Database dynamically to the Database you are currently logged into*/;

&DATABASE = Lower(%DbName);

/* Open the file and delete it off of the file server*/;

&file = GetFile(“&Path | &DATABASE | &FileName, “W”, “A”, %FilePath_Absolute);
&file.Delete();

Want to hear about some of the great upcoming changes coming to PeopleSoft and PeopleTools? Then check out this webinar replay: PeopleSoft Technology Roadmap. See what is next for PeopleSoft Fluid User Interface, Oracle’s full suite of cloud-ready lifecycle management tools (including PeopleSoft Cloud Manager), simplified analytics, and more.

How to Delete A File With PeopleCode