People Code

28
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 Data Validation

Transcript of People Code

Page 1: People Code

IntroductionWhat 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 classesWhy PeopleCode?

• Carry out the business rules of the organization• Simplifying Data Processing• Data Validation

Page 2: People Code

PeopleCode EventsRecord Field Component

Record FieldComponent 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

Page 3: People Code

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• Can be associated with record fields and component record fields

Page 4: People Code

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 • Can degrade performance of the application

Page 5: People Code

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•can be associated with record fields and components

Page 6: People Code

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 • Can be associated with record fields and component search records

Page 7: People Code

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• Can be associated with record fields and component record fields

Page 8: People Code

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 • Error and Warning cannot be used in this event

Page 9: People Code

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• Can be associated with record fields and component records

Page 10: People Code

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

Page 11: People Code

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

Page 12: People Code

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• Does not fire if run from a Component Interface

Page 13: People Code

Component ProcessorThe 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

Page 14: People Code

Search ProcessingSearchInit

Search Dialog Display

User Action

Search Save

Search and fill list

Build Prompt List

Buffer Search Key values

List Select

Unique value ReturnedNo Values or Rows found

Partial key value returned

Search Button

Page 15: People Code

Default ProcessingField 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

Continue Processing

Page 16: People Code

Default Processing

RowInit

PostBuild

Activate

Display Page, Wait for the user action

From Start Page To Page Display

Page 17: People Code

Events After User Changes Field

Page 18: People Code

PeopleCode Variables

System variablesSystem 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 variablesThese 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:GlobalValid for the entire session.ComponentValid while any page in the component in which it's defined stays active.LocalValid for the life of the PeopleCode program or function in which it's defined.

Page 19: People Code

PeopleCode Functions

Built-inThe standard set of PeopleCode functions described in PeopleCode Built-in Functions. These can be called without being declared.

InternalFunctions that are defined (using the Function statement) within the PeopleCode program in which they are called.

External PeopleCodePeopleCode functions defined outside the calling program - generally contained in record definitions serving as function libraries.

Page 20: People Code

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.

Page 21: People Code

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.

Page 22: People Code

Accessing Data Buffer

Page 23: People Code

Accessing data from Data BufferAccessing 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 ObjectExample: &ROWSET = GetRowset();

Record Object Example: &REC = &ROW.GetRecord(RECORD.EMPL_CHECKLIST);

Field Object Example: &FIELD = &REC.GetField(FIELD.CHECKLIST_CD);

Page 24: People Code

Example 1

The following PeopleCode can be used in SaveEdit for validation of employee idBefore saving

If Record1.Empid = 0 Then Error “Employee ID cannot be 0”;End-If;

Page 25: People Code

Example 2The following PeopleCode can be used in FieldEdit for assigning dearness allowancebased on the basic salary

Evaluate Record1.Basic When < 10000 Record1.DA = 2000; Break; When > 10000 Record1.DA = 4000;End-Evaluate;

Page 26: People Code

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

Page 27: People Code

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.• Preventing SQL Injection

Page 28: People Code

THANK YOU