PeopleCode Full Reference Guide
1. Basic Syntax
-- Single line comment
/* Multi-line comment */
Local string &name;
Local number &count;
&name; = "John";
&count; = 5;
2. Control Structures
If &count; > 0 Then
MessageBox(0, "", 0, 0, "Positive");
Else
MessageBox(0, "", 0, 0, "Not Positive");
End-If;
For &i; = 1 To 5
MessageBox(0, "", 0, 0, String(&i;));
End-For;
While &i; < 10
&i; = &i; + 1;
End-While;
Evaluate &grade;
When = "A"
MessageBox(0, "", 0, 0, "Excellent");
When-Other
MessageBox(0, "", 0, 0, "Other Grade");
End-Evaluate;
3. Functions
Function AddNumbers(&a; As number, &b; As number) Returns number
Return &a; + &b;
End-Function;
Local number ∑ = AddNumbers(10, 20);
4. Try-Catch (Error Handling)
Try
/* risky code */
Local number &x; = 10 / 0;
Catch Exception &ex;
MessageBox(0, "Error", 0, 0, &ex.ToString;());
End-Try;
5. Arrays & Objects
Local array of string &arr;
&arr; = CreateArrayRept("", 3);
&arr;[1] = "One";
&arr;[2] = "Two";
MessageBox(0, "", 0, 0, &arr;[2]);
6. Records & Rowsets
Local Record &rec; = CreateRecord(Record.PERSONAL_DATA);
&rec.EMPLID.Value; = "123";
&rec.SelectByKey;();
MessageBox(0, "", 0, 0, &rec.NAME.Value;);
Local Rowset &rs; = GetLevel0()(1).GetRowset(Scroll.EMPL_DATA);
Local Row &row; = &rs;(1);
&row.PERSONAL;_DATA.NAME.Value = "John Doe";
7. SQL in PeopleCode
SQLExec("SELECT COUNT(*) FROM PS_PERSONAL_DATA", &count;);
Local SQL &sql; = CreateSQL(
"SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", &emplid;);
While &sql.Fetch;(&name;)
MessageBox(0, "", 0, 0, &name;);
End-While;
8. File Handling
Local File &file; = GetFile("/tmp/test.txt", "W", "A", %FilePath_Absolute);
&file.WriteLine;("Hello World");
&file.Close;();
9. Events
/* Common Component Events */
FieldChange – runs when field changes.
RowInit – runs when row is initialized.
SavePreChange – before saving data.
SavePostChange – after saving data.
PageActivate – when page is activated.
10. Application Classes (OO PeopleCode)
class HelloWorld
method SayHello();
end-class;
method HelloWorld
end-method;
method SayHello
MessageBox(0, "", 0, 0, "Hello from Class!");
end-method;
Local HelloWorld &obj; = create HelloWorld();
&obj.SayHello;();
11. Component Interfaces
Local ApiObject &ci; = GetCompIntfc(CompIntfc.HR_PERSONAL_DATA);
&ci.EMPLID; = "123";
&ci.Get;();
MessageBox(0, "", 0, 0, &ci.NAME;);
12. Integration Broker (IB)
Local Message &msg; = CreateMessage(Operation.SEND_EMPLOYEE);
Local Rowset &rsData; = &msg.GetRowset;();
&rsData;(1).EMPLID.Value = "123";
%IntBroker.Publish(&msg;);