PeopleCode

Display Text Catalog on a PeopleSoft Page

A new functionality in PeopleSoft is the ability to use Text Catalog instead of Message Catalog and display the text on the page. Some main advantages, as I’ve noticed, by using Text Catalog is the ability to use HTML and make text effective dated.

So, lets get right into it and see how is this done!

Navigate to Set Up HRMS > Common Definitions > Text Catalog and Notepad > Maintain Text Catalog then go ahead and create your text catalog that we will be using.

%Concat Meta-SQL in PeopleCode

%Concat resolves to the database-specific concatenation operator so you don't have to guess which way it is done.

The following PeopleCode uses the %Concat meta-sql meta-variable:

SELECT INSTRUCTOR, FIRST_NAME %Concat ' ' %Concat LAST_NAME
FROM %Table(PSU_INSTR_TBL)

On SQL Server, this code resolves to:
SELECT INSTRUCTOR, FIRST_NAME + ' ' + LAST_NAME
FROM PS_PSU_INSTR_TBL

Defining PeopleCode Events

Every PeopleCode program is associated with a PeopleSoft Application Designer definition and with an event. Events are predefined exit points in the component processor flow. As each point is encountered, the event runs PeopleCode for that event each definition.

The below is an attempt to map the 17 Component Processor PeopleCode events to the Component Process Flow:

Search Action Events:
SearchInit, SearchSave

Add to Date using PeopleCode

I came across the below PeopleCode built-in function when trying to find a way to add a month to %date. So, here it is as PeopleSoft explaines it.
My code ended up being like this :

/*Adding one month to system date*/
AddToDate(%date, 0,1,0);

Syntax
AddToDate(date, num_years, num_months, num_days)
Description
Use the AddToDate function to add the specified number of years, months, and days to the date provided.

Stop or Prevent Inserting Grid Rows Via PeopleCode

The PeoleCode below will prevent users from inserting more than 2 rows on a grid. The "+" button will disappear the moment a 2nd row is added by a user. I have place this code on a record field under rowinit event.
If GetRowset().ActiveRowCount = 1 Then
GetRowset().InsertEnabled = True;
Else
GetRowset().InsertEnabled = False;
End-If;

FTP a File Using PeopleCode

Here is a function to FTP a file on a server using PeopleCode.
Local string &FtpUserID;
Local string &FtpPassword;
Local string &FtpURL;
Function ftp_file;
&FtpUserID = “user_id”;
&FtpPassword = “password”;
&FtpURL = “directory_name/subdirectory_name”;
&targetFile = “File_Name”;
/* Set ftp string */
&Ftp_my_file = “ftp://” | &FtpUserID | “:” | &FtpPassword | “@” | &FtpURL;
/*** It is always a good practice to check to see if local file exists before trying to transfer it ***/

Display Only the Last 4 Digits of a Social Security Number

The PeopleCode below will only display the last 4 digits of a social security number. I have placed the code in a Component PostBuild event and it works perfect.

DERIVED_HR.SOCIAL_SECURITY_NUMBER = Replace(DERIVED_HR.SOCIAL_SECURITY_NUMBER, 1, 7, “XXX-XX-);

Here, I’m using the replace PeopleCode built-in function. The functions takes the value from a the above field, starts at position 1 and replaces the 1st 7 characters with the string “xxx-xx-”.
The result:
After this code gets executed, SSN on a page should show up as xxx-xx-5623

Delete a File Using PeopleCode

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 a Group Box on a Page Using PeopleCode

To hide a group box and all the fields placed in it on a PeopleSoft page use the code below in a page “Activate” event.

HR_LBL_WRK.STATUS_LBL.Visible = False;

Where HR_LBL_WRK is the record name, and STATUS_LBL is the field record. Double click on the Group Box to see its record properties (1st tab).
For the Group box and all the fields in it to be completely hidden, make sure the “Hide Border” and “Adjust Layout for Hidden Fields” on the Label tab are checked and the “Hide all Fields when Group Box Hidden” on the Use tab is also checked.

Check Email Address and Type on a PeopleSoft Grid

The grid looks like this:

PeopleCode to restrict Xlat Values

What I would like to accomplish is every time the user adds a new email address i would want to check for the following:
1. Check for blank email type
2. Edit to check for '@' character
3. Check if email address is blank
4. Check for duplicate email type in the same grid