Introduction
What is PeopleCode?• Structured programming language provided by PeopleSoft
• Associated with application designer definition and events
• Syntax resembles that of any other structured
programming languages
• Has in-built functions and supports objects and classes
Why PeopleCode?
• Carry out the business rules of the organization
• Simplifying Data Processing
PeopleCode Events
Record Field Component Record Field
Component Record
Component Page Menu
FieldChange FieldDefault FieldEdit FieldFormula PrePopup RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave Workflow FieldChange FieldDefault FieldEdit PrePopup RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave PostBuild PreBuild SavePostChg SavePreChg Workflow Activate ItemSelected
FieldEdit
• Used to validate the contents of a field, supplementing the standard system edits
• Displays message if data does not pass validation • Message can be both Error or Warning
• Fires on the specific field and row that just changed
• Can be associated with record fields and component record fields
FieldChange
• Used to recalculate page field values
• Change the appearance of page controls
• Perform other processing that results from a field change other than data validation
• Fires on the specific field and row that just changed
FieldDefault
• Enables to programmatically set fields to default values when they are initially displayed
• Can be associated with record fields and component record fields • An Error or Warning issued will cause a runtime error and force
cancellation of the component
FieldFormula
• If a field data is changed, the row is not marked as changed in this event
• Often used in FUNCLIB_ (function library) record definitions to store shared functions
• Only associated with record fields
SavePreChange
• Fires after SaveEdit completes without errors
• Provides one final opportunity to manipulate data before the system updates the database • Not field-specific: it triggers PeopleCode on all fields and on all rows of data in the component
buffer.
• Can be associated with record fields, components, and component records
SaveEdit
• Fires whenever the end-user attempts to save the component • Can be used to validate the consistency of data in component fields • Usually used when validation involves more than one component field
• Not field-specific: it triggers associated PeopleCode on every row of data in the component buffers, except rows flagged as deleted
SavePostChange
• Fires after Component Processor updates the database • Error or Warning statement cannot be used in this event
• System issues a SQL Commit after SavePostChange PeopleCode completes successfully
• Can be associated with record fields, components, and component records
SearchInit
• Generated just before a search dialog, add dialog, or data entry dialog box is displayed
• Control processing before the end-user enters values for search keys in the dialog box
• Will not fire if run from a Component Interface
SearchSave
• Executed for all search key fields on a search dialog, add dialog, or data entry dialog
box after the end-user initiates ‘search’
• Is used to control processing after search key values are entered, but before the search based on these keys is executed
• Also used to force the user to enter a value in at least one field • Does not fire when values are selected from the search list
• can be associated with record fields and component search records
PrePopUp
• Fires just before the display of a pop-up menu
• Can be used to control the appearance of the Pop-up menu
RowDelete
• Fires whenever end-user attempts to delete a row of data from a page scroll.
• Triggers PeopleCode on any field on the row of data that is being flagged as deleted
• Does not trigger programs on Derived/Work records
• Can be associated with record fields and component records
RowInit
• Fires the first time the Component Processor encounters a row of data
• Used for setting the initial state of component controls
• Triggers PeopleCode on all fields and on all rows in the component buffer
RowInit Exceptions
• Component Processor doesn't run RowInit PeopleCode for some record fields
• If record can be initialized entirely from the keys for the component, RowInit does not run
• Following must be true for RowInit to not run
• The record is at level 0
• Every record field that is present in the data buffers is also present in the keys for the component
• Every record field that is present in the data buffers is display-only
RowInsert
• Generated when end-user adds a row of data
• RowInit always fires after RowInsert, so same code should not be present in the two.
• Triggers PeopleCode on any field on the inserted row of data • Warning and Error cannot be used in this event
RowSelect
• Fires at the beginning of the Component Build process in any of the Update action modes (Update, Update/Display All, Correction)
• Used to filter out rows of data as they are being read into the component buffer
• Rarely used as it's inefficient to filter out rows of data after they've already been selected
• Can be associated with record fields and component records
Workflow
• Executes immediately after SavePreChange and before the database update that precedes SavePostChange
• Main purpose is to segregate PeopleCode related to workflow from the rest of the application’s PeopleCode
• Only PeopleCode related to workflow should be in workflow programs
• Not field-specific: it triggers PeopleCode on all fields and on all rows of data in the component buffer
PreBuild
• Fires before the rest of the component build events
• Also used to validate data entered in the search dialog
• Only associated with components
PostBuild
• Fires after all the other component build events have fired
• Usually used to hide or unhide pages
• Can also be used to set component variables
• Associated only with components
Activate
• Fires each time the page is activated • Each page has its own Activate event
• Main purpose of the Activate event is to segregate the PeopleCode that is related to a specific page from the rest of the application’s PeopleCode • Can use this event for security validation
• Can only be associated with pages
• Is valid only for pages that are defined as Standard or Secondary
ItemSelected
• Fires whenever the end-user selects a menu item from a pop-up menu • Executes in the context of the page field from where the pop-up menu is
attached
• Only associated with pop-up menu items
Component Processor
The Component Processor is the PeopleTools runtime engine that controls processing of the application from the time the end-user requests a component from an application menu through the time that the database is updated and processing of the component is complete.
Component Processor Flow
•Reset state and the search record •After the Search
•Fields Action Events •Row Action Events •Save Action Events •Pop-up Menu
Search Processing
SearchInit
Search Dialog Display
User Action
Search Save
Search and fill list
Build Prompt List
Buffer Search Key values
List Select
Unique value Returned No Values or Rows found
Partial key value returned Search Button
Default Processing
Field Level Default Processing
Result
Field Formula
Field Level Default Processing
Else
Result
Any field blank, another field changed
Any field blank, another field changed Else
Default Processing
RowInit
PostBuild
Activate
Display Page, Wait for the user action
PeopleCode Variables
System variables
System variables provide access to system information. System variables have a prefix of the '%' character, rather than the '&' character. Use these variables wherever you can use a constant, passing them as parameters to functions or assigning their values to fields or to temporary variables.
User-defined variables
These variable names are preceded by an "&" character wherever they appear in a program. Variable names can be 1 to 1000 characters, consisting of letters A-Z and a-z, digits 0-9, and characters #, @, $, and _.
Scope of Variables:
Global
Valid for the entire session.
Component
Valid while any page in the component in which it's defined stays active.
Local
PeopleCode Functions
Built-in
The standard set of PeopleCode functions described in PeopleCode Built-in Functions. These can be called without being declared.
Internal
Functions that are defined (using the Function statement) within the PeopleCode program in which they are called.
External PeopleCode
PeopleCode functions defined outside the calling program - generally contained in record definitions serving as function libraries.
PeopleCode Functions & Methods
PeopleCode also supports methods. The main difference
between a built-in function and a method is:
•A built-in function, in your code, is on a line by itself, and
does not (generally) have any dependencies. You do not
have to instantiate an object before you can use the
function.
•A method can only be executed from an object, using
dot notation. You have to instantiate the object first.
Data Buffer Access
• A field object, which is instantiated from the Field class, is a single instance of data within a record and is based on a field definition.
• A record object, which is instantiated from the Record class, is a single instance of a data within a row and is based on a record definition. A record object consists of one to n fields.
• A row object, which is instantiated from the Row class, is a single row of data that consists of one to n records of data. A single row in a component scroll is a row. A row may have one to n child rowsets. For example, a row in a level two scroll may have n level three child rowsets.
• A rowset object is a data structure used to describe hierarchical data. It is made up of a collection of rows. A component scroll is a rowset. You can also have a level 0 rowset.
Accessing data from Data Buffer
Accessing Level 0
The following code instantiates a rowset object, from the Rowset class, that references the level 0 rowset, containing all the page data. It stores the object in the &LEVEL0 variable.
Example : &LEVEL0 = GetLevel0();
Rowset Object
Example: &ROWSET = GetRowset();
Record Object
Example: &REC = &ROW.GetRecord(RECORD.EMPL_CHECKLIST);
Field Object
Example 1
The following PeopleCode can be used in
SaveEdit for validation of employee id
Before saving
If Record1.Empid = 0 Then
Error “Employee ID cannot be 0”;
End-If;
Example 2
The following PeopleCode can be used in
FieldEdit for assigning dearness allowance
based on the basic salary
Evaluate Record1.Basic
When < 10000
Record1.DA = 2000;
Break;
When > 10000
Record1.DA = 4000;
End-Evaluate
;
Debugging your Application
• Access the PeopleCode debugger
• Setup debugging Environment
• Set PeopleCode debugger log options
• Compile PeopleCode programs at once
• Use the Find In feature
How to improve performance (
with reference to PeopleCode)?
• Reducing Trips to the Server • Using Deferred Mode
• Using the Refresh Button • Using Warning Messages • Optimizing SQL
• Moving PeopleCode to a Component or Page Definition • Writing More Efficient Code
• Watch references
• Break Statement in Evaluate • Avoid Implicit conversion • Using of SQL object.