Você está na página 1de 29

PeopleCode

Day 1
[A comprehensive 2 day tour on the capabilities of the SQR language and its usage in PeopleSoft]

PeopleCode

People Tools - 3 Day Class

PeopleCode
Table of Contents 1.1: Review 3 days Agenda .........................................................................3 Day 1:.........................................................................................................4 1.2: Understanding PeopleCode Development Environment .............................4 Activity 1 - Using PeopleCode Editor .......................................................... 11 1.3: Understanding Component Processor & Events ...................................... 11 Activity 2 Walkthrough on event execution............................................... 12 1.4: PeopleCode Events Listing ................................................................... 12 1.5: Understanding the execution order of events and PeopleCode..................14 Activity 3 Walkthrough on Component Processing ..................................... 17 The following table maps the 17 Component Processor PeopleCode events to the Component Processor flow. .......................................................................... 22 1.6: Writing and Debugging Programs ......................................................... 23 Activity 4 Debugging a program..............................................................25 1.7: Object Orientation in PeopleCode ......................................................... 27

PeopleCode
1.1: Review 3 days Agenda

We will be covering this section on PeopleCode over a period of three days. A brief breakup of the material is as given below Day 1 will cover following areas Understanding PeopleCode (PC) development environment Understanding Component Processor & Events PeopleCode Event Listing Writing and Debugging Programs Object orientation in PeopleCode

DAY 2 will cover following areas Explaining component buffer Understanding execution flow in multi level pages Understanding PeopleCode language Understanding events in detail Understanding Add mode Processing Understanding Deferred Processing

DAY 3 will cover following areas Classes and accessing data using classes Using Variables Built-in functions

PeopleCode

Day 1: 1.2: Understanding PeopleCode Development Environment

This topic will cover the following concepts Describe PeopleCode and how it is used How is PeopleCode written Where in the Application PeopleCode is written Debugging tools

PeopleCode is the proprietary language used within PeopleSoft environment to write advanced validation rules and processes. It is extensively used within the application. PeopleCode uses a Visual basic kind of notation, has events similar to what you would see in a Visual basic environment. All the programs written are stored in database tables and can be associated with different types of definitions like, records, pages, components, App Engine, Integration tools etc. The program gets compiled at the time of first execution and stays in the cache of App Server. Subsequent executions happen based on this compiled cache version. The program gets recompiled if it undergoes a change. PeopleCode is used for: Control presentation of information to the user. Validate user inputs. Perform calculations and data manipulation. Maintain data integrity. Update database tables. Manage portal navigation. Integrate with other PeopleSoft applications. Integrate with third-party applications. Manage workflow. Administer security.

PeopleCode
PeopleCode is written within PeopleSoft component processor flow i.e. code written at various events that get triggered when a component is loaded or when user takes some action within a component e.g. editing a field, inserting, updating or deleting a row or saving information etc. However there are other areas as well where PeopleCode is written. Some of these are: Application Engine: PeopleSoft Application Engine is a PeopleTool that helps you develop, test, and run background SQL processing programs. In PeopleSoft Application Engine, a program is a set of SQL statements, PeopleCode, and program control actions (that enable looping and conditional logic), defined in PeopleSoft Application Designer, that performs a business process. You can use Application Engine for straight, row-by-row processing, but the most efficient Application Engine programs are written to perform set-based processing. PeopleSoft Application Engine PeopleCode provides an excellent way to build dynamic SQL, perform simple IF/ELSE branching, set defaults, and perform other operations that don't require a trip to the database. It also enables you to reference and change active Application Engine state records Component Interface: This object opens the front end in a black box form which can be accessed within PeopleSoft or outside PeopleSoft as well. This provides a flexibility to open PeopleSoft logic and rules to non PeopleSoft applications. Messages: Messages are part of PeopleSoft integration broker and they provide asynchronous reply / response kind of functionality for a PeopleSoft system to interact with other PeopleSoft on non PeopleSoft systems. Workflow: To check the rules and dynamically define the routing of work items. PeopleSoft also delivers two PeopleCode functions, Virtual Approver and Virtual Router, which simplify implementation of approval rule processing functionality. Development Environment PeopleCode is written using Application Designer which is the integrated PeopleSoft Application development environment.

PeopleCode
Locating PeopleCode Programs Most PeopleCode programs are associated with an Application Designer definition and with an event. Each definition has an event seta group of events appropriate to that definition. Events are predefined exit points either in the Component Processor flow or in the program flow (for Messages, Component Interfaces, or Application Engine programs). As each event is encountered, the PeopleCode program that is associated with that definition and that event executes. A definition can have zero or one PeopleCode programs for each event in its event set. One of the basic and most common places to write PeopleCode is in Record. Screen shot below shows a record definition, which shows the fields in the record and events available against each of the fields. An entry with tick indicates the location where the code is written.

PeopleCode
Double clicking the tick will open the PeopleCode editor with the specific program location.

In the above window, program is displayed. This program relates to COMPANY_TBL record and is written on field EFF_STATUS for SaveEdit event. Once you are in the editor, you can click on the two drop down boxes at the top of the editor to select other fields and/or events to view the program that may have been written on this record. An Entry with bold indicates that a program exits. The screen shot below shows all the fields which have some PeopleCode written against some event.

The screen shot below shows that field COMP_POINTS_VALUE has code written against two events PrePopup and RowInit.

PeopleCode

There is another way to navigate and open PeopleCode. If you have a record definition included in a project, you can expand the record and it will show all the fields in that record. A (+) will appear for those fields that have code associated with it. Clicking the (+) sign will expand and show the events against which code is written. This is displayed as a lightning bolt followed by the name of the event. You can click on the event name to open the associated program in PeopleCode editor.

Note: You also see the path of the code in the menu header which displays the <Record name>.<field name>.<event name>

PeopleCode
Code in Record versus Component PeopleCode cannot be written at field definition level. Field definitions only act as data dictionary and have no meaning individually. It is always the Record.Field that you access with code. So the first level of writing the code is against a specific event for a field in a record. From version 8, there is another place where the code is written i.e. at component level. To examine the code, you need to open the component, click on the Structure tab and then right click while on a definition, highlight the View PeopleCode and click. Example below shows the component for accessing Company table and associated code.

The example below shows the code associated with COMPANY_TBL record. Here we observe that there is no code associated with the field EFF_STATUS at component level for the component COMPANY_TABLE.GBL. We also know that there is a PeopleCode associated with this field at Record level as shown earlier.

PeopleCode

What this means is that one can write the code at Record.Field level or Component.Record.Field level. Both get executed. However, writing code at Record.Field level makes it available in all components that have the Record.Field displayed at any of the pages in that component. But writing code at component level makes it available only at component and will not be executed at other components using the same Record.Field. Features of PeopleCode editor The PeopleCode Editor includes the following features: Automatically formats the code when you save, including indents, spaces, and capitalization. Validates your syntax. Any syntactic errors are reported so that you may fix them. Supports drag and drop of definition names or text from the Project Workspace, another definition window, or another Editor window. Allows you to open any definition or view PeopleCode on any definition referenced in the program with a right-click. Provides context-sensitive help for any PeopleCode built-in function, system variable, or meta-SQL function. Automatically backs up your program every keystroke. PeopleCode Editor is color coded.

PeopleCode
The default color code for the PeopleCode Editor is: Keywords, built-in functions, and class definitions are blue. Quoted strings are red. Comments are green. With the Editor open, select Edit, Display Fonts and Colors.

To change the default colors:

Activity 1 - Using PeopleCode Editor Open the record <STU_INITIALS>_PERSONAL and add the following code at <STU_INITIALS>_NAME field, FieldEdit event: If ^ = <STU_INITIALS>_emplid then Warning Employee name is same as id; End-if; Click on Save and see how the code gets formatted and validated. Also observe how ^ is changed to the field name where the code is being written. Referencing Fields in PeopleCode PeopleCode programs can refer to any field on any record definition provided the field referenced is in the buffers while the program is being executed. When a field is referred to by just its name, PeopleCode assumes that the field is on the same record definition where the program is attached. If the field comes from another record definition, the field name must be qualified using the appropriate record name. A shortcut can be used to refer to the field on which the PeopleCode program is attached. Instead of typing the entire field name, the ^ character can be used. When PeopleSoft formats PeopleCode, it will replace the ^ with the appropriate record name and field name. 1.3: Understanding Component Processor & Events

The Component Processor is the PeopleTools runtime engine that controls processing of an application from the time that a user requests a component from an application menu until the database is updated and processing of the component is complete. It controls the order of execution of PeopleCode events based on the users action.

PeopleCode
Activity 2 Walkthrough on event execution Change the value of the Lines on Paysheet field to 200, there is PeopleCode that is written in the FieldEdit event of the field that causes a PeopleCode to be triggered and this in turn displays a message as shown:

Observe that the user action caused the FieldEdit PeopleCode event to be triggered. If there is code written in the FieldEdit event associated with that record field, the program is executed. The program is executed just once, on the specific field and row of data. 1.4: PeopleCode Events Listing

What are events? As defined in PeopleBooks, Events are predefined exit points either in the Component Processor flow or in the program flow. As each event is encountered, it fires on each component, triggering any PeopleCode program associated with that component and that event. Each definition in PeopleSoft Application Designer can have an event set, that is, a group of events appropriate to that definition. A definition can have zero or one PeopleCode programs for each event in its event set.

PeopleCode
Below is a list of PeopleCode Events associated with different objects in PeopleSoft: Record Field Events Component Record Field Events FieldChange FieldDefault FieldEdit PrePopup Component Record Events Component Events Page Events Menu Events

FieldChange FieldDefault FieldEdit FieldFormula PrePopup RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave Workflow

RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave

PostBuild PreBuild SavePostChg SavePreChg Workflow

Activate

ItemSelected

As you can see from above, Record field events have common set with Component Record Field events or Component Record events. E.g. FieldEdit appears in Record Field Events column as well as Component Record Field Events Column. Both get fired at the same point. However, they provide different level of granularity for maintaining the code. A code written at Record Field will be executed on all components which have this field on one of the pages. While writing the same code at Component Record Field level will execute it only within that specific event. When you write a new piece of code, you should consider the usage and place the code accordingly, at record or component level. There is no better approach and it depends on the usage. Record field level code gets executed first and then the component Record field level code is executed. Events after Field value changes
Record.recordA.fielda.FieldEdit -> Component.recordA.fielda.FieldEdit -> Record.recordA.fielda.FieldChange -> Component.recordA.fielda.FieldChange ->

Events After User Saves


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

PeopleCode
Component.recordB.SaveEdit Record.recordA.fielda.SavePreChange -> Record.recordA.fieldb.SavePreChange -> Component.recordA.SavePreChange Record.recordB.fielda.SavePreChange -> Record.recordB.fieldb.SavePreChange -> Component.recordB.SavePreChange Component.SavePreChange Record.recordA.fieldA.WorkFlow -> Record.recordB.fieldB.WorkFlow -> Component.Workflow Record.recordA.fielda.SavePostChange -> Record.recordA.fieldb.SavePostChange -> Component.recordA.SavePostChange Record.recordB.fielda.SavePostChange -> Component.recordB.SavePostChange Component.SavePostChange

The following table lists types of PeopleCode programs and where to access them in PeopleSoft Application Designer. PeopleCode Programs Record field Component record field, component record, and component Menu item Page field Location in PeopleSoft Application Designer Record definitions and page definitions Component definitions

Menu definitions Page definitions

1.5:

Understanding the execution order of events and PeopleCode

In PeopleSoft, the component is the representation of a transaction. Therefore, any PeopleCode that is associated with a transaction should be written within events associated with some level of the component. If you have code that should be executed every time a field is changed/entered, you should put it at the record field level.

PeopleCode
Before you write a PeopleCode program, you to need to decide three things: WHEN you want to have it runwhich event or events in the flow of the Component Processors are most appropriate for your rule. WHERE to place your PeopleCodeon which definition. WHAT to programthe code syntax. Component Processing from Page Start to Page Display 1. Before the end-user selects a component, the system is in reset state, in which no component is displayed. 2. Component Processor's flow of execution begins when the end-user selects a component from a PeopleSoft menu. This flow chart shows the flow for Search Processing

Reset state: How does a user typically access a page? o By selecting a content reference on the Menu Portal. The Component Processor determines the component and then displays the search page, on which the user selects a search key

Search page: If applicable, the search page is displayed so that the user can define the rows to be retrieved o On the search page, the user enters key or partial key values and clicks the Search button. Users can also select a row from the search list, if the data entered as key values return more than one row of data. The Component Processor uses these key values to build the SQL statements to select the application data from the database into application server memory and then to populate the component buffer o SQL Select: The SQL Select statements are sent to the database for execution, and the data is brought down from the database server into the

PeopleCode
application server. However, while the data is in memory, it is not yet loaded into the component buffer, which is later used by the Component Processor and PeopleCode. Data for the entire component is loaded, including all of its pages both those visible to and those hidden from the user. The processor treats a component as one logical unit of work at both data retrieval and database update This flow chart shows the flow for Component Build Processing

When a user selects a unique search key, the Component Processor retrieves all of the data that is needed for the entire component, then assembles the component, displays the first page, and waits for a user action. The Component Processor loops through each row selected from the database, loading it into the component buffer. When all rows have been loaded, the loop exits and processing continues.

PeopleCode
This row-loading process was implemented in earlier versions of PeopleSoft applications to enable developers to conditionally filter rows using RowSelect PeopleCode after the rows were loaded into memory, but before they were loaded into the component buffer Activity 3 Walkthrough on Component Processing Select the component Modify a person Enter an emplid, say, K, and click on the search button.

SELECT the value KCD001 from the list.

The Component Processor then:


- Performs a search from the database against the key value entered, and saves search key values for the component. - Retrieves from the database any data needed to build the component, and then builds the component, creating buffers for the component data. - Opens up and displays the component and waits for end-user action.

In the process, the SearchInit, SearchSave and Activate Events are executed. The first two events are available at both the Record Field level, as well as the Component Record Level. Any code written in these events will be executed when the Component opens up. The Activate Event is available only at the Page level.

PeopleCode
The component then opens up displaying the personal data for the EMPLID chosen.

PeopleCode
Component Processing based on User Action: This flow chart shows the flow for field action processing

PeopleCode
This flow chart shows the flow for row action processing

PeopleCode
This flow chart shows the flow for save action processing

There are different PeopleCode events that are triggered due to user Action. Events
RowInsert

Description
If a user inserts a row of data within a grid or a scroll area, the component Processor fires any code written in the RowInsert event.

RowDelete

If a user deletes a row of data within a grid or a scroll or a scroll area, the component Processor fires any code written in the RowDelete event.

FieldEdit FieldChange FieldDefault

If a user enters data on a page field, then leaves the field, the component Processor validates the data by performing standard edits (such as checking the data type and checking for values out of range etc.). If the data entered into the field do not pass the standard system edits, the Component Processor redisplays the page with an error or warning message and changes the fields color to usually red. Until the error is corrected, the

PeopleCode

Events

Description
Component Processor does not let the user to save changes or navigate to another field. If the contents of the field pass the standard system edits, the system redisplays the page.

PrePopUp

If a user clicks the pop-up icon next to a field, a pop-up menu appears. Any validation that needs to be done before the pop-up menu is displayed needs to be written into this event.

ItemSelected

A user can select an item from a pop-up menu to execute a command. Validations can be included in this event before a specific commands gets executed.

SaveEdit SavePreChange SavePostChange

A user save a component by clicking Save. If any component data has been modified, the Component Processor first validates the data in the component, and then updates the database with the changed component data. After the update, a SQL Commit command finalizes the changes.

The following table maps the 17 Component Processor PeopleCode events to the Component Processor flow.

PeopleCode
1.6: Writing and Debugging Programs

PeopleCode programs can be debugged using the PeopleCode Debugger. The PeopleCode Debugger is an integral part of the App Designer. The debugger allows you to set breakpoints (points at which you want to start debugging). After a breakpoint, a yellow arrow indicates the current line of code being executed. You can also step through code. The PeopleCode debugger also has provision to inspect the values of all kinds of variables - global, component, and local. These windows are generally called Watch Windows. For those familiar with programming using Visual Basic, in the VB editor, the PeopleCode debugger is almost identical to the debugging in VB. PeopleCode Debugger PeopleCode debugger has following features: It is integrated with the Application designer which is the IDE for all PeopleSoft development. One can set breakpoints and step through the code. There is a window that opens at the bottom which displays the variable values being available at that point in program. Once can also see the function parameters. The screen shot below shows how to enter into Debug mode.

PeopleCode
You highlight the codeline where you want to set the breakpoint

Press F9 or click on Debug to get the options for setting the breakpoint

Shown below is the field where the code will be executed when a value is changed and one tabs out of the field. i.e. FieldEdit event.

PeopleCode

The window below shows the executed code.

Activity 4 Debugging a program In this activity, Students are required to set a breakpoint on one of the codes at COMPANY_TBL record field events and debug the execution.

PeopleCode
Setting Trace A PeopleCode trace creates a file displaying information about PeopleCode programs processed from the time you start the trace. There are four ways to start a trace: The Trace PeopleCode page Click the link to set a startup trace on your PeopleSoft sign on page. Use the Trace utility on Configuration Manager. Include the SetTracePC PeopleCode built-in function in a program. Setting trace through Trace PeopleCode Page Navigation: PeopleTools, Utilities, Debug, Trace PeopleCode

Setting trace through sign-on page Signon Trace only works from the signon page when the URL includes ?cmd=login. The parameter &trace=y is case sensitive

PeopleCode

1.7:

Object Orientation in PeopleCode

Object oriented programming is all about thinking everything in terms of classes and objects. In earlier PeopleCode versions, it used to be very difficult to reference an App Designer Object like a page, record, or component. However, with the release of PeopleTools8.x, this has been made extremely easy. PeopleSoft delivers a set of classes of objects that you can use with PeopleCode. The delivered classes may or may not have a graphic user interface equivalent; some are representations of data structures that occur only at runtime. With PeopleCode, you can manipulate data in the data buffer easily and consistently. These classes enable you to write more readable and maintainable code. In addition, you can extend the existing classes or create your own. Classes A class is the formal definition of an object. It is a template used to create an instance of an object in runtime. A class defines the properties and the methods associated with the object. PeopleSoft delivers predefined classes (e.g. Field, Record, Rowset, Array and File etc). You can create your own classes using the Application class. You can also extend the functionality of the existing classes using the Application class. Objects An object represents a unique instance of a class. Each object has its own values for the variables (properties) belonging to its class and can be manipulated using methods associated with that class. This is the same for classes provided by PeopleSoft and for classes you create yourself. After you create an instance of a class, the properties can be read/changed using methods. Properties define the characteristics or state. Some properties are read-only and cannot be changed e.g. Name or Author. Other properties can be changed, such as Value or Label. Object Instantiation The process by which an object is created based on the template defined by the class. Local field &tstField &tstField = GetField();

PeopleCode
Changing Properties To set or get characteristics of an object, or to determine the state of an object, you must access its properties through dot notation syntax. Follow the reference to the object with a period, followed by the property, and assign it a value: Object.Property = Value The following example hides the field &tstField: &tstField.Visible = False Dot notation is also used to execute methods. Follow the reference to the object with a period, then with the method name and any parameters the method takes. The format is generally: Object.method(); You can string methods and property values together into one statement. The following example strings together the GetField method with the Name property: If &REC_BASE.GetField(&R).Name = &REC_RELLANG.GetField(&J).Name Then .<do something> When you assign one object to another, you do not create a copy of the object, but only make a copy of the reference. In the following example, &O1 and &O2 refer to the same object. The assignment of &O1 to &O2 does not allocate any database memory or copy any part of the original object. It makes &O2 refer to the same object to which &O1 refers. Local Array of Number &O1, &O2; &O1 = CreateArray(1, 2, 3); &O2 = &O1;

PeopleCode
Another Example For example, you have a record class and a field class that is PS delivered. These classes can be instantiated to reference record and field objects that have been created through App Designer. Below is a small piece of Object Oriented code:

&RECORD = CreateRecord(SI_COMPANY_TBL); &FIELD = &RECORD.GetField(FIELD.COMPANY);

As seen above, a record object &RECORD for the record SI_COMPANY_TBL is created using Peoplecode. Then, the next statement references the field COMPANY within that record. Data values for fields can also be assigned by means of PeopleCode.

Você também pode gostar