July 15, 2009

PeopleSoft Technical: PeopleCode

Types of PeopleCode Events
- Record Field PeopleCode
- Page PeopleCode
- Component PeopleCode
- Component Record PeopleCode
- Component Record Field PeopleCode
Note: Component code fires before component record code, which fires before component record field code.


Component Record and Component Record Field Events





PeopleCode Event Summary
An event is the way that the PeopleSoft Application Designer associates a program with a definition. Each event is a predefined point in the component processor flow, commonly referred to as the program flow. When an event is encountered in the program flow, it fires on a component, which triggers the PeopleCode program associated with it to process. Each definition can be a single definition or it can be one of an event set, a group of PeopleCode events that fire in a program flow. A definition can fall outside of the component processor. External processes include: Application Engine programs, component interfaces, and application packages. There is also the standard sign-on event, which allows for the creation of a session with the PeopleSoft application and resides external to any and all events.


PeopleTools Menus
PeopleSoft has two types of menus: standard menus and pop-up menus. Each type of menu is defined separately as a standalone definition within your project. PeopleCode can be used only on pop-up menus, not in standard menus. There is only one event on a pop-up menu to write PeopleCode in—ItemSelected. This event fires whenever a menu item is selected from a pop-up menu.

Defining PeopleCode Pop-Up Menu Items
  1. Create a pop-up menu.
    a. In the menu definition, double-click an existing pop-up menu.
    b. Double-click the empty rectangle at the bottom of the menu.
  2. Enter a name and a label for the item.
  3. Select PeopleCode from the Type group to enter the PeopleCode.
  4. Click OK to close and then save your project.


Debugging and Message Functions
  • MessageBox is one of the most powerful debugging tools in your tool chest as a PeopleSoft developer.
  • MessageBox is the preferred method by PeopleSoft. But a WinMessage is a good way to make sure the code you are working on is the code being called.
  • Another really terrific way of debugging is to create a log file and log off anything important. With this method you trap the events in a log, and if something occurs you can trace it back and get a very good idea of what occurred.
  • PeopleCode supports Java objects and PeopleSoft delivers the log4j lib in the PS_HOME/class directory. The following methods can be invoked within the log4j: debug(), info(), warn(), error(), fatal(), and log(). These methods generate log requests during application execution so your code can be riddled with them and they will log off and never disturb your customers.
  • If Logic can be used in PeopleCode to turn logging on and off.

Message Catalog

Message catalogs represent the messages you want to go out to your customers in the production environment. They are the messages that you want displayed when a wrong value is typed or a button is used incorrectly. PeopleSoft delivers thousands of these in its applications and you can create thousands of your own. With PeopleSoft 8.5 the location of the message catalog is stored in a new record named PSMSGCATDEFN. The old record was PS_MESSAGE_CATALOG.


Declaring Variables
PeopleCode variables (except object variables) are all preceded with “&” and then the data type of the assignment statement.
  • ANY
    This variable is used when the data that is being returned into this type is unknown. The use of the type ANY will allow PeopleTools to determine the best match for the variable. Undeclared local variables by default become ANY variables.
  • BOOLEAN
    This variable is a single bit type that can be TRUE(1) or FALSE(0).
  • DATE
    This variable is a standard date that in PeopleCode is in the format YYYY-MM-DD and in the Oracle database is in the format DD-MM-YYY.
  • DATETIME
    This variable is exactly what it says—the date with the time—and is in the following format: YYYY-MM-DD-HH.MI.SS.SSSSSS.
  • TIME
    This variable is expressed as HHMISS. When you use a function that uses TIME, it returns a numeric value.
  • NUMBER
    A NUMBER variable is a decimal value or integers; it can be any number that has decimal points. NUMBER and STRING are the most used variable types in PeopleCode.
  • FLOAT
    This variable represents a floating decimal point number. The FLOAT variable is a number using a machine floating binary point or double precision. And by default the NUMBER data type in PeopleCode is a floating decimal point representation.
  • INTEGER
    This variable is a whole number with no decimal points.
    Tips on when to use NUMBER, INTEGER, or FLOAT variables:
    Use NUMBER when you are unsure, and it will be the primary default way to declare numbers. Use INTEGER when you are counting items; a good example is when you count rows in a rowset. Use FLOAT only when you are performance tuning and the application is already working—and you know what the result should be.
  • STRING
    This variable can be a combination of letters, special characters, and numbers. It is
    initialized by enclosing the declared string in quotes. You can use either single or double quotes. When you need to enclose a string within a string, one type of quote is enclosed by another type. The “best practice” is to enclose strings in double quotes and embedded strings in single quotes.
  • OBJECT
    OBJECT variables have their own data types:
    - PeopleCode Data Buffer Access Types Field, Record, Row, and Rowset.
    - PeopleCode Display Data Types AnalyticGrid, Chart, Grid, GridColumn,
    and Page.
    - PeopleCode Internet Script Data Types Cookie, Request, and Response.
    - PeopleCode Miscellaneous Data Types AESection, AnalyticInstance, Array, Crypt, Exception, File, Interlink, BIDocs, JavaObject (can only be declared as type Local), Message, MCFIMInfo, OptEngine, PostReport, ProcessRequest, RowsetCache, SoapDoc, SQL, SyncServer, TransformData (can only be declared as type Local), XmlDoc, and XmlNode (objects can only be declared as type Local).
    - Global ApiObject Data Type Objects Session, PSMessages collection, PSMessages, all tree classes (trees, tree structures, nodes, levels, and etc.), and query classes.
    - Local ApiObject Data Type Objects Meta SQL, Meta HTML, System
    Variables, and RowSet.

Variable Scopes in PeopleCode
There are three basic variable scopes in PeopleCode: Local, Component, and Global.
There are two types of Local variables: an ordinary Local program variable and a Local function variable. A Local program variable is declared and available during the duration of that program, and a Local function variable is available while the function is called and activated.
  • Global A Global variable is valid during the entire session and can be reset during the session. It is important to understand that its life span is associated with the session and you need to remember to clear and reassign depending on when you plan to use the variable. It is used less often because not that many items need to be valid during the entire session.
  • Component A Component variable is only valid when the object or page that it was created on is valid. This type of variable is used in component interface coding.
  • Local A Local variable is valid during the PeopleCode program or function where the variable was defined. It is the most common variable declaration.


Logic Statements
  • If-Then-Else
    One of the most common and easiest to use PeopleCode logic statements is the if-then-else statement. It allows you to control the flow of your program, it allows for branching, and it allows processing dependent upon a set of terms.
  • Evaluate
    Another form of branching in PeopleCode is done using the Evaluate statement. It is used when you have multiple conditions that exist and you need to evaluate each of them.
  • For
    For statements can be very useful tools. They are excellent when you need to execute statements multiple times, and you need to loop or iterate through them.
  • While
    The While statement is another way to loop and allow for repeated statements in PeopleCode. The loop will process until the expression is false. In a lot of aspects the For loop and the While loop are very similar. Any break within a loop returns control to the next highest level, and processing will continue with the next statement after the loop ends. While loops do have a danger of being written as a runaway loop, with For loops you do have more control.
  • XLAT
    An XLAT item returns true in a component interface if the value is being retrieved from an XLAT table.
Note1: Use /* at the beginning of the comment and */ at the end. This is usually used when a block of code is commented out. REM will remark out a single line of code. Put a ; at the end of the REM statement to terminate and note the end of the comment.
Note2: Use <* at the beginning of the comment and *> at the end. This form of commenting is used to comment within another comment.
Note3: Do not use /+ +/ syntax to make comments, they will be removed by the system the next time you compile or save your PeopleCode as these are used in comments in application classes.

No comments:

Post a Comment