PeopleTools | Understanding the file server and ‘current working directory’.
A. Why the Problem?
In numerous places throughout a PeopleSoft system, you will find yourself having to interact with an external file server, such as saving a BI Publisher report or importing a CSV file. Working out the exact location can be a tricky business due to a few factors:
- The process can be run in various contexts, such as online PeopleCode directly on a page, an App Engine run on the Process Scheduler, or an App Engine run on the developer’s local machine. Each context will have a different working directory.
- The file process can be run on different databases, and therefore different servers. In most environments, a process run on a Test server will end up in a different place to that run on a Production server. You may also have to contend with multiple App Servers, each of which will use its own directory path.
- Some PeopleCode file functions (‘GetFile’ for instance) accept a parameter such as ‘%FilePath_Absolute’ or ‘%FilePath_Relative’. This parameter specifies the directory that the system must use for file manipulation. If ‘%FilePath_Absolute’ is entered, the full directory path (including file name) must be provided. If ‘%FilePath_Relative’ is entered, this indicates that the file should be retrieved or saved to the ‘current working directory’. However, this doesn’t give you any clue as to which folder this happens to be at the point of executing the code.
B. Home Directory vs Working Directory
To understand the mystery of file locations, it will help if we think of two different directory types, the ‘Home’ directory and the ‘Working’ directory. The Home Directory is typically where the application ‘lives’. In other words, this is where the executable and other core program files are located. The Working Directory is used by the system to temporarily save files that use ‘%FilePath_Relative’ or don’t have a file path specified.
The Home Directory and the Working Directory are almost always separate directories. The more permanent application files should not be mixed with temporary, working files.
C. Home Directory
In PeopleSoft terms, the Home Directory is the App Server home directory (or the user’s local PC if a process is being run directly on the client). The App Server home directory can be determined by the ‘GetCWD’ function, which stands for ‘Get Current Working Directory’:
MessageBox(0, "", 0, 0, "App Server Home Directory is " | GetCWD() );
You may be thinking that PeopleCode is greatly confusing things by giving you a ‘current working directory’ that isn’t a working directory at all. This is true. Files should not be saved in the immediate directory supplied by ‘GetCWD’. However, ‘GetCWD’ comes in useful if you have a process that needs to save a file across different servers and file structures.
For instance, you may have a ‘reports’ directory that exists on each of your database instances, but the file path to access that directory differs according to the server:
/u03/apps/psft/ps_cfg/appserv/CS9DEV/reports /u02/apps/psft/ps_cfg/appserv/CS9TST/reports /u02/apps/psft/ps_cfg/appserv/CS9PRODA/reports /u02/apps/psft/ps_cfg/appserv/CS9PRODB/reports
‘GetCWD’ can supply you with the initial part of the directory path for the current database instance, meaning you can write code such as this to save into the ‘reports’ directory:
&dest_file = GetCwd() | "/reports/REPORT_NAME.pdf";
D. Working Directory
To recap, PeopleTools uses the Working Directory for functions that specify ‘%FilePath_Relative’, or any other file interaction where the directory path is unknown.
The working directory is determined by three environmental variables, in the following order of priority (ie only if one value is blank does it then try the next):
- PS_SERVDIR (with ‘/files’ added on the end)
- TEMP (for App Engines only)
To determine the values of each of these variables, you can use the ‘GetEnv’ function, in association with ‘MessageBox’, to display the contents of the variable:
MessageBox(0, "", 0, 0, "PS_FILEDIR is " | GetEnv("PS_FILEDIR") ); MessageBox(0, "", 0, 0, "PS_SERVDIR is " | GetEnv("PS_SERVDIR") ); MessageBox(0, "", 0, 0, "TEMP is " | GetEnv("TEMP") );
Similar to ‘GetCWD’ above, ‘GetEnv’ can help you when dealing with multiple databases and servers. ‘GetEnv’ can provide the initial part of the directory path for the current program context, allowing for cross-platform code.