Category: PeopleCode

Create Directory Listing of Files In App Engine

Need to know dynamically which files are in a given folder?

May 2018 Update:  You can use function FindFiles to do this.

Also, apologies on the Ampersand.  We are working on making it not be &.

 &file_names = FindFiles(&file_loc, %FilePath_Absolute);

The code further in this article is the old way to do this.

The code below will allow you to list all of the files in a given directory, then allow you to open each file.  It could be useful to read which files have been recently added to an upload folder.  I used this code to read which files had recently been placed in the process scheduler working folder (first SQLExec in code example).

Details:  We run a system command to get a directory listing, and we send that output to a new file, in the same directory.  Then we open that new file and review which files were found.

/*Setup the Slash variable*/
If &OS = "Windows" Then 
    &slash = "\";
else 
    &slash = "/";
End-if;
/*Get the current working folder - You may want to use a static folder where files are being uploaded to - If you use this SQLExec, process instance &ProcInst*/
SQLExec("SELECT PRCSOUTPUTDIR FROM PSPRCSPARMS WHERE PRCSINSTANCE = :1", &ProcInst, &DirectoryLocation); 

/*Setup the filename to output to.*/
&DirectoryFileName = "FileListing_" | &ProcInst | ".filelisting"; 

/*Setup the folder to write the file to*/ 
&DirectoryListing = &DirectoryLocation | &slash | &DirectoryFileName; 

If &OS = "Windows" Then 
    &CMD_TO_RUN = "cmd.exe /c dir """ | &DirectoryLocation | """ /b > """ | &DirectoryListing | """";
Else 
    &CMD_TO_RUN = "ls """ | &DirectoryLocation | """ > """ | &DirectoryListing | """";
End-If; 

/*It is always best to Commit the work before running Exec*/ 
CommitWork();
try 
    &return_value = Exec(&CMD_TO_RUN, %Exec_Synchronous + %FilePath_Absolute); 
catch Exception &e 
    MessageBox(0, "", 0, 0, "Error Found. Exception is " | &e | " with return value " | &return_value); 
    MessageBox(0, "", 0, 0, "Command sent was " | &CMD_TO_RUN); 
    MessageBox(0, "", 0, 0, "Going to Next step in App Engine."); 
end-try; 

Local File &f1, &f2; 
&f1 = GetFile(&DirectoryListing, "r", %FilePath_Absolute); 
While &f1.ReadLine(&RowOfData); 
/*Skip the file if the filename matches our Directory File name*/ 
    If &RowOfData <> &DirectoryFileName Then
        MessageBox(0, "", 0, 0, "Processing Filename " | &RowOfData); 
        &Columns_array = Split(&RowOfData, "."); /*Useful to read the file extension. Use variable Upper(&Columns_array [2])*/ 
        &f2 = GetFile(&DirectoryLocation | &slash | &RowOfData, "r", %FilePath_Absolute);
        While &f2.ReadLine(&F2RowOfData);
            /*Process the row of data, using variable &F2RowOfData*/
        End-While;
    End-If;
End-While;

&f1.Close();

Step Through PeopleCode

In PeopleTools 7.5, we had Application Reviewer for debugging PeopleSoft. For PeopleTools 8.4x and 8.50, since the panels are now pages on the browser, how do we debug peoplecode (interactively)? The answer follows:

How to Step Through PeopleCode

To step through PeopleCode that is running on the browser, do the following. The first four steps will be handled by your PeopleSoft Administrator.

  1.  Ensure the appropriate PSDBGSRV Listener Port is specified on the App Server.
  2.  At least two PSAPPSRV processes should be configured on the App Server.
  3.  The Service Timeout parameter should be set to zero.
  4.  The “Enable PSDBGSRV Server Process” should be set to Yes on the App Server.
  5.  Launch Application Designer on the workstation. Log in using 3-tier and your userid.
  6.  Under menu item Debug, select “Enter Debug Mode”.
  7.  Launch PeopleSoft through the browser, and use the same userid as in step 5.
  8. Go the page needing review.
  9. On the debug menu in App Designer, select either debug at start or create new breakpoints (similar to 7.5).
  10. Go back to the browser and trigger the PeopleCode. Once the breakpoint is triggered, the App Designer will wait for you to respond. The web browser will appear to be loading the next page (“Processing” might flash).

 

Special Notes

  1. May not work on Windows 95 and 98 machines.
  2. Debug will slow performance.
  3. Debug should not be run in Production.
  4. Use a user id that is not being shared (use your own id, not VP1).
  5. Some clients have seen connection problems for other users after the debug has been performed. If this happens, perform debugging in the evening or during times that few users are in the database. If the connection problem occurs, then reboot the Application and Web Servers. Since the debug should not be run in Production, this minor occurrence can be handled by rebooting the proper servers/services.