Академический Документы
Профессиональный Документы
Культура Документы
Introduction
What is PeopleCode?
PeopleSofts own Proprietary language
Used to incorporate sophisticated business rules into PeopleSoft applications Gives the capability to enhance applications beyond the capability of the PeopleTools
Accessing PeopleCode
Prior to PeopleTools 8
Record Field Menu Item
PeopleTools 8
Record Field Page Component Menu Item (Pop-Up only) Component Interface Message and Message Channel Application Engine
3
Editing PeopleCode
PeopleCode supports the standard text editing features and functions such as Save, Undo, Cut, Paste, Find and Replace. No Need to Format PeopleCode Just be concerned about the correct Syntax Does not format anything within the Quotes Fieldnames are converted to Uppercase Variable match their First Occurrence PeopleCode is Case-Insensitive, except for quoted literals
Referencing Fields
Referring to a field by Assumes that ^
Fieldname Recordname. Fieldname
PeopleCode Statements
Statement can be a Declaration Assignment Program Construct (Such as a Warning Statement or a conditional loop) Subroutine calls And so on PeopleCode statements should end in a semicolon
PeopleCode Statements
Comments
Remark Comments; Or REM Comments; Or /* Comments */ Or /* Comments <* Inside nest *> Comments */
Assignments
Addition Subtraction Unary Negation Multiplication Division Exponentiation String Concatenation + * / ** | PRICE + TAX GROSS - TAX -10 PRICE * QUANTITY ANNUAL_PAYMENTS / 12 DIMENSION ** 3 CITY | ,| STATE
PeopleCode Statements
IF statement
If condition then <PeopleCode Statements>; Else <PeopleCode Statements>; End-if; You can have Nested IF statements Relational Operators
= != , <> > , >= < , <= Equal To Not Equal To Greater than , Greater than or Equal to Less than , Less Than or Equal to
Relational Operators
NOT AND OR
PeopleCode Statements
ERROR statement
Error (<message>);
WARNING statement
Warning (<message>);
EVALUATE statement
Evaluate <field or &variable> When = <Value1> <PeopleCode statements>; -------------------------------When-Other <PeopleCode statements>; End-Evaluate
BREAK statement
Break;
PeopleCode Statements
For Loop
For <&variable> = <Start-Value> to <End-Value> [step <stepvalue>] statement; statement; End-For;
While Loop
While <condition> statement; statement; End-While;
Repeat-Until Loop
Repeat statement; statement; Until <condition>;
10
Component Processor
Controls how PeopleSoft manages applications from Initial data retrieval through updating the database Throughout the process, Component Processor applies PeopleCode at different time PeopleCode events fire at particular times and in particular sequence during flow of execution Whenever you code PeopleCode to enforce a business rule, you will need to know three things
WHEN you want the PeopleCode to execute WHERE to place the PeopleCode WHAT PeopleCode syntax to use
11
Component Processor
General Areas where the Component Processor Performs PeopleCode
During the Search Process Before the displaying the Page After a field Changes After inserting and deleting a row After page is saved After processing pop-menus
Search Events
SearchInit fires before the search dialog box appears to initialize fields or apply defaults to search After entering appropriate search values and Search push button is clicked, SearchSave PeopleCode will perform. It is used to either force a user to enter a value into the dialog, restrict the ranges of codes that can be added, or edit the valued entered Both the Search PeopleCode event will perform if the PeopleCode is attached to the search records to fields that appear in the dialog (Search Keys and Alternate Search Keys)
Before displaying the Component to a User, seven PeopleCode events are invoked RowSelect, PreBuild, FieldDefault, FieldFormula, RowInit, PostBuild and Activate. If User changes an action, The component processor displays the page again, the Component Processor performs FieldDefault, FieldFormula, and RowInit PeopleCode, if appropriate. PreBuild and PostBuild are executed only once when Component is built. Activate fires only when the user selects the page.
12
Component Processor
Field Action Events
FieldEdit and FieldChange are activated when the value of a field is changed FieldEdit validates the new value. FieldChange does the processing based on the new (and valid) value of the field
13
Component Processor
Pop-Up Menu Events
PrePopup event fires before the pop-up menu is displayed. This allows a PeopleCode program to conditionally alter the appearance of one or more menu items. For instance, a menu can be disabled (grayed out) or hidden temporarily. If the user selects a menu item from the Pop-up list that has a PeopleCode program attached to it, then the ItemSelected event will fire.
Add Action
Add Processing is handled quite a bit differently by the Component Processor. For rows added with a new search (high-level) key, a flow of RowInit, SearchInit, FieldEdit, FieldChange, SaveEdit, and then finally SearchSave is processed prior to User receiving the GUI.
Deferred Processing
In PIA architecture all the component buffers are on the Application Server and all the PeopleCode is executed on the Application Server. This can result in a performance impact when there is a lot of field action processing that is FieldEdit and FieldChange peoplecode, along with standard system field edits. Mitigating the Performance Impact No automatic trip back to server. In other words, if a field is changed and there is no FieldEdit or FieldChange PeopleCode on the field, record defaults and FieldDefault PeopleCode will not be run until some other action causes the trip to the server Developers are encouraged to put FieldEdit validations in SaveEdit to save trips to server Developers have the option of enabling the deferred processing, which will will automatically defer standard fields edits, FieldEdit and FieldChange events.
14
PeopleCode Events
SearchInit (SrI) PeopleCode
Performs before the search record dialog box displays. Controls processing before a user enters values in the search key and alternate search keys Only performs only if the search record with search keys and alternate search key is associated with the peoplecode
PSUSERSELF_SRCH.OPRID = %OperatorId; SetSearchDialogBehaviour(0);
15
PeopleCode Events
PreBuild PeopleCode
Component PeopleCode event Fires before the rest of the component build events Often used to hide or unhide pages Also used to set global or component scope variables that can be used later by PeopleCode located in other events
If %Mode <> A Then
Hide(field.ADD_MODE_IND);
End-If;
16
PeopleCode Events
RowInit (Rin) PeopleCode
Performs the first time the component processor encounters a row of data. This occurs for every new row of data brought into the component after the buffer allocation process. It also occurs when a users performs a RowInsert, but just on the one new row of data.
If None(PS_STUDENT_TBL.STUDENT_ID) Then
Gray(PS_STUDENT_TBL.STUDENT_ID);
End-If;
PostBuild PeopleCode
Component PeopleCode event Used to Calculate values and set display characteristics of an object
If AMM_PUBLIST.NRID < 1 Then
GetPage(Page.AMM_RAWNRXML).Visible = False;
End-If;
Activate PeopleCode
Page PeopleCode event Fires each time a page is activated Page Processing, such as enabling a field or hiding a scroll
SetGridLables(%Panel, Record.AMM_CHNL_SECVW);
17
PeopleCode Events
FieldEdit (FEd) PeopleCode
Performed after a field has changed and a new value fo the field satisfies the standard system edits Used to validate the contents of the field Assignments statements should not be performed in FieldEdit
If PS_HDR.ORDER_STATUS <> IN Then Error Msgget(20000,1,Message not found); End-If;
RowInsert PeopleCode
Performed when a new row is added Used to Override effective-dated processing, or to auto number new rows of data
18
PeopleCode Events
RowDelete (RDe) PeopleCode
Performed when a new row is deleted Used to caculate running totals or prevent a row from being deleted After the RowDelete finishes, the Component processor performs FieldDefault and FieldFormula peopleCode.
If PS_HDR.ORDER_STATUS <> IN Then Error Msgget(20000,1,Message not found); End-If;
RowInsert PeopleCode
Performed when a new row is added Used to Override effective-dated processing, or to auto number new rows of data
19
PeopleCode Events
SaveEdit (SEd) PeopleCode
Performed when tries to save the component Used to validate data before it is updated to the database SaveEdit makes sure that all the changes have been made before the validation takes place
20
PeopleCode Variables
User-defined variables are required for temporarily holding the data in PeopleCode All variable names must begin with & and can be maximum in 18 characters in length, including the ampersand. Fields from Derived/Work Records add more flexibility to the system as they can be placed on the pages
21
PeopleCode Variables
Variable Type
Local
Duration (Scope)
Program
Purpose
Passes values within a single program Passes values between all program within a component Passes values between all components for a user session Hold values for reference from any code Display values on a page and passes values between all programs with a single component
Disadvantage
Cannot display on a page
Component
Component
Global
PeopleSoft Session
System
Application Installation
Derived/Work Fields
Component
22
PeopleCode Variables
LOCAL COMPONENT GLOBAL <type> &VarName; <type> &VarName; <type> &VarName;
<type> = Number String Boolean Date Time Datetime Object Any Float Integer
System Variables
%Date %Time %UserId %Mode %Page
23
24
Eg: following creates a field object that references an employees name Local Field &Field; /* Declare */ &Field = GetField(STUDENT_DATA.STUDENT_NAME); /* Instantiate */ Eg: following returns a record object for a record already in the page buffer Local Record &REC1, &REC2; /* Declare */ &REC1 = GetRecord(); /* Instantiate */ &REC2 = CreateRecord(RECORD.COURSE_TBL); /* Instantiate */
25
27
Function Process_Rowset(&ROWSET as Rowset) For &I = 1 to &ROWSET.RowCount For &J = 1 to &ROWSET.RecordCount &RECORD = &ROWSET.GetRow(&I).GetRecord(&J); [do stuff to the data here] &RECORD.Update(); End-For; End-For; End-Function;
28
PeopleCode Functions
CATEGORIES OF FUNCTIONS
Internal-PeopleCode: A PeopleCode routine that is stored in the same program where it is used. Defined by a Function statement. External-PeopleCode A PeopleCode routine that is stored in a different program from where it is used. Defined by a declare statement with the keyword PeopleCode External-Non-PeopleCode A common C++ (or other language routine that is loaded from DLL. Defined by a Declare statement with the keyword library.
FUNCTION STATEMENT
Function <function-name> (<parm1>,<parm2>,) statement; statement; End-Function;
29
PeopleCode Functions
DECLARING A FUNCTION
Declare Function <Function-Name> PeopleCode <RecordName.FieldName> FieldEvent;
CALLING A FUNCTION
PeopleCode Functions are called using the name of the function and passing the correct number of parameters in paratheses. The number of parameters need to match the parameters used by the function
Declare Function assign_student_id PeopleCode FUNCLIB.STUDENT_ID FieldFormula; if PSU_STUDENT_TBL.STUDENT_ID = NEW then assign_student_id(PSU_STUDENT_TBL.STUDENT_ID); end-if;
RETURNS STATEMENT
Function <Function-name> (<parm1>,) returns <type> Returns <Expression>;
30
PeopleCode Functions
BUILT-IN FUNCTION Page Buffer Functions: Modify fields, values & variables within the buffers Scroll Buffer Functions: Manipulate scroll area records for various purposes Logical Functions: Check if values exist for a field Date & Time Funcs: Used to easily calculate & manipulate dates String Functions: With with character strings Double-Byte Char Funcs: Supports the languages that utilise double-byte chars Number functions: Work with numeric values DOS functions: Control DOS processes API functions: Include WinExec WorkFlow, RemoteCall etc
31
PeopleCode Functions
MESSAGE CATALOG FUNCTION MsgGet MsgGet (<MessageSet>, <MessageNum>,DefaultMsgTxt[,<Bind1>,]) MsgGetText MsgGetText(<MessageSet>, <MessageNum>,DefaultMsgTxt[,<Bind1>,])
32
PeopleCode Functions
Gray/Ungray and Hide/Unhide FUNCTION Procedural Method Gray(<recordname.fieldname>); UnGray(<recordname.fieldname>); Object Based Method <Recordname.fieldname>.Enabled = False; <Recordname.fieldname>.Enabled = True; IsChanged, IsNew, IsDeleted FUNCTION
PeopleCode Functions
Other Important Functions FUNCTION PriorValue RTrim, Ltrim, Substring OriginalValue SetCursorPos Method
Local Field &Qty; &Qty = GetField(PSU_PO_DTL.QTY); If All(&Qty.OriginalValue) then &Orig_Qty = &Qty.OriginalValue; if &Qty.value > &Orig_Qty then Error MsgGet(20000,30,Message Not Found); End-If; End-If;
34
Accessing Buffer
ActiveRowCount <RowSetName>.ActiveRowCount TotalRowCount <RowSetName>.TotalRowCount Value,FetchValue and UpdateValue <RowNumber>.<RecordName.Fieldname>.value /* Object Based */ FetchValue(<RecordName.Fieldname>,<RowNumber>) /* Procedural */ UpdateValue(<RecordName.Fieldname>,<RowNumber>) /* Procedural */
DATA Buffer Classes Rowset Data structure used to describe a hierarchical data Row single row of data in a component scroll Record single instance of data within a row Field single instance of data within a recordw
35
Accessing Buffer
&RowSet = GetLevel0(); &RowSet = GetRowSet(Scroll.RecordName); &RowSet = &Row.GetRowSet(Scroll.RecordName); &Row = &RowSet.GetRow(n); &Record = &Row.GetRecord(RECORD.RecordName); &Field = &Record.GetField(FIELD.Fieldname);
36
Traversing Buffer
TRAVERSING = ROWSET > ROW > RECORD > FIELD
Declare the data buffer objects Local Rowset &RS0, &RS1; Local Row &Row0, &Row1; Local Record &Rec1; Local Field &Field1; &RS0 = GetLevel0(); &Row0 = &RS0.GetRow(1); OR &Row0 = &RS0(1); /* Level0 and level1 rowsets */ /* single row at level0 and level1 */ /* record */ /* field */
&Rec1 = &Row1.GetRecord(Record.Recordname); OR &Rec1 = &Row1.Recordname; &Field1 = &Rec1.FieldName; Then you can use sa &Field1.Enabled = False;
37
38
39
40
41
42
43
44
45
46
47
48
49
PeopleCode Variables
50