PeopleCode Program Triggers

This section provides an overview of PeopleCode program triggers and discusses how to:

  • Access PeopleCode programs.

  • Associate execution order of events and PeopleCode.

PeopleCode can be defined on events associated with a record field, a component, a component record, and many other definitions. During the course of the component processor’s flow of execution, these PeopleCode events (or exit points) are encountered in a specific sequence. When an event is encountered, the component processor runs any PeopleCode for that event on each definition.

The following definitions have events that are part of the component processor flow:

Items

Event Triggers

Components

Programs associated with a component definition.

Component records

Programs associated with a component record.

Component record fields

Programs associated with a component record field.

Pages

Programs associated with a page definition.

Record fields

Programs associated with a specific field of a record definition.

Menu items

Programs associated with a menu item.

Suppose a user changes the data in a page field, and then presses Tab to move out of the field. This user action initiates the FieldEdit PeopleCode event. The FieldEdit event affects only the field and row where the change took place.

If you have two FieldEdit PeopleCode programs, one associated with the record field and a second associated with the component record field, both programs execute, but only on the specific field and row of data. The FieldEdit PeopleCode program associated with the record field is executed first, and then the FieldEdit PeopleCode program associated with the component record field is executed.

By contrast, suppose a user has opened a component for updating. As part of building the component, the component processor encounters the RowInit event. This event triggers any RowInit PeopleCode programs on every record field on every row of data in the component. In a scroll area with multiple rows of data, each RowInit PeopleCode program is executed once for each row.

In addition, if you have RowInit PeopleCode associated with both the record field and the component record, both programs are executed on every row of data in the component. The RowInit PeopleCode program associated with the record field is executed first, and then the RowInit PeopleCode program associated with the component record is executed. If you set the value of a field with the record field RowInit PeopleCode, and then reset the field with the component record RowInit PeopleCode, the second value appears to the user.

When you develop with PeopleCode, you must consider when and where your programs are triggered during execution of the component processor flow in addition to what that program executes.

This section discusses how to:

  • Access PeopleCode programs.

  • Understand the execution order of events and PeopleCode.

Every PeopleCode program is associated with a PeopleCode event and is often referred to by that name, such as RowInit PeopleCode or FieldChange PeopleCode. These programs are accessible from, and associated with, different items. The following table lists items and associated events.

Note: During search processing in update modes or add mode, the SearchInit and SearchSave events (in the Component Record column of the table) are available only for the search record associated with a component.

Component Events

Component Record Events

Component Record Field Events

Page Events

Record Field Events

Menu Events

PostBuild

PreBuild

SavePostChg

SavePreChg

Workflow

RowDelete

RowInit

RowInsert

RowSelect

SaveEdit

SavePostChg

SavePreChg

SeachInit

SearchSave

FieldChange

FieldDefault

FieldEdit

PrePopup

Activate

FieldChange

FieldDefault

FieldEdit

FieldFormula

PrePopup

RowDelete

RowInit

RowInsert

RowSelect

SaveEdit

SavePostChg

SavePreChg

SearchInit

SearchSave

Workflow

ItemSelected

The following table lists types of PeopleCode programs and where to access them in Application Designer.

PeopleCode Programs

Location in Application Designer

Components*, component records*, and component record fields

Component definitions

Pages

Page definitions

Record fields

Record definitions

Menu items

Menu definitions

* PeopleCode programs can be associated with components and component records outside of Application Designer. The PeopleSoft Related Content Framework can be used to map application class PeopleCode programs to component and component record events. This allows custom PeopleCode programs to be defined for a component without customizing the component definition in Application Designer. These custom PeopleCode programs can be configured to run before or after any PeopleCode program defined for the same event from the component definition.

Note: While the PeopleSoft Related Content Framework is used to complete this configuration, these PeopleCode programs do not constitute or render as related content.

In PeopleSoft systems, the component is the representation of a transaction. Therefore, any PeopleCode that is associated with a transaction should be in events associated with some level of the component itself (component, component record, or component record field). If you associate code with the correct transaction, you do not have to check for the component that is issuing it (such as surrounding your code with dozens of If %Component = statements). Consequently, this makes record definitions more reusable, and your code is more maintainable. However, code that should be executed every time a field is edited should be at the record field level and not placed on the component.

For example, if you have start and end dates for a course, you would always want to make sure that the end date was after the start date. Your program to check the dates would go on the SaveEdit at the record field level.

All similarly named component events are executed after the like-named record event. The PeopleCode program associated with the record field event is executed first, and then the PeopleCode program associated with the like-named component event is executed. If you set the value of a field with the record field PeopleCode, and then reset the field with like-named component PeopleCode, the second value is displayed to the user.

Events After Field Changes

The following events occur after a user changes a field:

Record.recordA.fielda.FieldEdit -> Component.recordA.fielda.FieldEdit -> 
Record.recordB.fieldb.FieldEdit -> Component.recordB.fieldb.FieldEdit ->
Record.recordA.fielda.FieldChange -> Component.recordA.fielda.FieldChange -> 
Record.recordB.fieldb.FieldChange -> Component.recordB.fieldb.FieldChange ->

Image: Flow of events and PeopleCode programs after a user changes a field

The following diagram shows the flow of events and PeopleCode programs after a user changes a field.

Flow of events and PeopleCode programs after a user changes a field

Events After User Saves

The following events occur after a user saves:

Record.recordA.fielda.SaveEdit -> 
Record.recordA.fieldb.SaveEdit -> 
Record.recordA.fieldc.SaveEdit -> 
Component.recordA.SaveEdit 

Record.recordB.fielda.SaveEdit -> 
Record.recordB.fieldb.SaveEdit -> 
Record.recordB.fieldc.SaveEdit -> 
Component.recordB.SaveEdit

Record.recordA.fielda.SavePreChange -> 
Record.recordA.fieldb.SavePreChange -> 
Record.recordA.fieldc.SavePreChange -> 
Component.recordA.SavePreChange

Record.recordB.fielda.SavePreChange -> 
Record.recordB.fieldb.SavePreChange -> 
Record.recordB.fieldc.SavePreChange -> 
Component.recordB.SavePreChange

Record.recordA.fieldA.WorkFlow -> 
Record.recordB.fieldB.WorkFlow -> 
Record.reocrdC.fieldC.WorkFlow
Component.Workflow

Record.recordA.fielda.SavePostChange -> 
Record.recordA.fieldb.SavePostChange -> 
Record.recordA.fieldc.SavePostChange -> 
Component.recordA.SavePostChange

Record.recordB.fielda.SavePostChange -> 
Component.recordB.SavePostChange
Component.SavePostChange

Image: Flow of PeopleCode programs after SavePostChange event

The following diagram shows the event flow of PeopleCode programs after SavePostChange event.

Flow of PeopleCode programs after SavePostChange event

Note: SaveEdit does not fire for deleted rows, but SavePreChange, Workflow, and SavePostChange do.