Category Archives: PeopleCode

Checking for duplicates on a Grid

I recently used this snippit of code and found it useful. I wanted to post it here so I had it for future reference. Credit:

/* Check for data duplicates on a grid. */
Local Row &row1, &row2;
Local number &r, &r1;

&rs = GetLevel0().GetRow(1).GetRowset(Scroll.grid_table);

For &r = 1 To &rs.ActiveRowCount
/*Get grid row*/
&row1 = &rs.GetRow(&r);
/*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/
For &r1 = 1 To &rs.ActiveRowCount
&row2 = &rs.GetRow(&r1);
/* if this is a different row, and the field_name value matches then throw an error*/
If &r1 <> &r And
&row1.grid_table.field_name.Value = &row2.grid_table.field_name.Value Then
MessageBox(0, "", 0, 0, "Error. Duplicate values are not allowed.");

Automatic Backup of PeopleCode

A PeopleCode program is automatically saved to a file while you’re working on it. This checkpoint occurs at the following times:
• Every 10 keystrokes.
• On a save command, just prior to the save being executed (in case the save doesn’t actually execute because the code is invalid).
• When another PeopleCode program is selected to be edited (if you have two PeopleCode editor windows open at the same time, and you move from one to the other).

The file is saved to your temp directory (as specified in your environment), in a file with the following name:

PPCMMDDYY_HHMMSS.txt where MMDDYY represents the month, date and year, respectively, of the checkpoint, and HHMMSS represents the hour, minute and second, respectively.

The top of the checkpoint file contains the following information:

[PeopleCode Checkpoint File]


If your PeopleCode program is saved successfully, any checkpoint files associated with that program are automatically deleted.

Escape Character in PeopleCode

I was working on a project and came across a scenario where I needed to escape a character in PeopleCode. Specifically a double quote. In order to do that you have to just repeat the double quote:

(notice the double quotes prior to and at the end of IdentityFile)

Local integer &execute;
Local string &cmd;

&PS_HOME = LTrim(RTrim(GetEnv("PS_HOME"), "/"), "/");

&cmd = "sftp -o ""IdentityFile=/" | &PS_HOME | "/user/sshkeys/private/sftp-key"" sftp@* /" | &PS_HOME | "/attachments/";
&execute = Exec(&cmd, %Exec_Synchronous + %FilePath_Absolute);

Evaluate &execute
When = 0
MessageBox(0, "", 30001, 1, "Files moved Successfully.");
When = 1
MessageBox(0, "", 30001, 1, "Files moved Successfully with an exit code of 1.");
MessageBox(0, "", 30001, 1, "Exit code did not return 0. &execute = " | &execute);

PeopleCode MessageBox to display messages

PeopleCode’s MessageBox can be used to display messages on the screen or in a log. It can be used for issuing warnings, indicating lack of information, or to see the value of certain variables while developing. If the code is running on a page, record or component, the message will be displayed on screen, but using it within a process such as an Application Engine, the message will be written in the log file.


MessageBox(style, title, catalog_message, number_message_catalog, default_text [,parameters] )

/*We indicate a catalog number and message number which does not exist to display the default message*/


/* If the message and catalog exist,the description defines for this message is shown*/
/* If the message doesn´t exist, the default message is displayed*/
MessageBox(0,””,30000,1,”Message could not be found”);

/* To display the value of a variable we can use the following statement*/
MessageBox(0,””,99999,99999,”variable1″ | &var1);