Sei sulla pagina 1di 108

PeopleCode

y
l
n

Volume I Activity Guide

O
e

I
A

&
l
a

D17669GC10

n
I
e

1.0
April 2004

l
c
a

D40576

r
O

n
r
te

s
U

Copyright 2004, 2005, Oracle. All rights reserved.


This document contains proprietary information and is protected by copyright and other intellectual property laws. You may
copy and print this document solely for your own use in an Oracle training course. The document may not be modified or
altered in any way. Except where your use constitutes "fair use" under copyright law, you may not use, share, download,
upload, copy, print, display, perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part
without the express authorization of Oracle.
The information contained in this document is subject to change without notice. If you find any problems in the document,
please report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This
document is not warranted to be error-free.
If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United
States Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS
The U.S. Governments rights to use, modify, reproduce, release, perform, display, or disclose these training materials are
restricted by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract.
Oracle, JD Edwards, and PeopleSoft are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be
trademarks of their respective owners.

y
l
n

O
e

I
A

&
l
a

n
r
te

r
O

l
c
a

n
I
e

s
U

CONTENTS
Preface

PeopleCode.........................................................................................................................v
Typographical Conventions and Visual Cues .....................................................................v
Related Documentation ......................................................................................................vi

Lesson 1

Course Overview ...............................................................................................................1

Lesson 2

Technology Overview........................................................................................................3

Lesson 3

Using PeopleCode Development Tools ............................................................................5


Activity 1: Reviewing the Application Development Process ........................................6
Activity 2: Using the PeopleCode Editor ........................................................................9
Activity 3: Debugging a PeopleCode Program..............................................................12

Lesson 4

Describing the Component Processor............................................................................15


Activity 4: Watching the Search Events Run ................................................................16
Activity 5: Watching the Component Build Events Run...............................................18
Activity 6: Watching the Row Action Events Run........................................................20
Activity 7: Watching the Save Action Events Run........................................................22
Activity 8: Examining Deferred Processing ..................................................................23
Activity 9: Choosing the Right Events ..........................................................................25

y
l
n

O
e

Lesson 5

Writing PeopleCode Programs ......................................................................................27

Lesson 6

Understanding PeopleCode Events................................................................................29


Activity 10:
Using SearchInit to control the Search Page ...........................................30
Activity 11:
Synchronizing the Student Table with the Customer Table....................32

Lesson 7

Using PeopleCode Variables...........................................................................................37


Activity 12:
Using Derived Work Fields.....................................................................38
Activity 13:
Setting Up a Variable Prompt Table Edit................................................41

Lesson 8

Using Built-In Functions.................................................................................................43


Activity 14:
Using Built-In Functions.........................................................................44

Lesson 9

Writing PeopleCode Functions ......................................................................................47


Activity 15:
Writing Functions....................................................................................48

Lesson 10

I
A

&
l
a

s
U

n
r
te

n
I
e

r
O

l
c
a

Explaining the Component Buffer .................................................................................51


Activity 16:
Determining the Contents of the Component Buffer ..............................52

Lesson 11

Accessing Data in the Component Buffer .....................................................................55

Lesson 12

Programming With Object-Oriented PeopleCode .......................................................57


Activity 17:
Using Object-Oriented Methods and Properties .....................................58

PeopleSoft Proprietary and Confidential

iii

PeopleCode

Contents

Lesson 13

Referencing Data in the Component Buffer .................................................................61


Activity 18:
Stepping Through the Data Buffer ..........................................................62
Activity 19:
Traversing the Data Buffer......................................................................67
Activity 20:
Accessing Multiple Occurs Levels..........................................................69

Lesson 14

Creating Custom Objects with Application Classes.....................................................71


Activity 21:
Writing an Application Class ..................................................................72
Activity 22:
Calling Hello World ................................................................................74
Activity 23:
Using Application Classes ......................................................................75

Lesson 15

Using Data Buffer Methods ............................................................................................79


Activity 24:
Using Select to Refresh Get Enrollments................................................80
Activity 25:
Adding the Flush Method........................................................................84

Lesson 16

Executing SQL in PeopleCode .......................................................................................87


Activity 26:
Updating Effort Spent With a SQLExec Statement ................................88
Activity 27:
Creating a SQL Definition ......................................................................89
Activity 28:
Using a SQL Object ................................................................................91
Activity 29:
Choosing the Best SQL Option ...............................................................92
Activity 30:
Executing SQL in PeopleCode................................................................94

Lesson 17

Final Course Activity ......................................................................................................97


Activity 31:
Using a Standalone Rowset to Track Overtime Hours............................98

Lesson 18

Course Review ...............................................................................................................101

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
iv

PeopleSoft Proprietary and Confidential

Preface

PeopleCode
Typographical Conventions and Visual Cues
This section discusses:

Typographical conventions.

Visual cues.

Typographical Conventions
This table contains the typographical conventions that are used in this guide:
Typographical Convention

Description

Bold

Indicates PeopleCode function names, method names, language


constructs, and PeopleCode reserved words that must be included
literally in the function call.

Italics

Indicates field values, emphasis, and PeopleSoft or other booklength publication titles. In PeopleCode syntax, italic items are
placeholders for arguments that your program must supply.

y
l
n

O
e

s
U

We also use italics when we refer to words as words or letters as


letters, as in the following: Enter the letter O.

I
A

KEY+KEY

Indicates a key combination action. For example, a plus sign (+)


between keys means that you must hold down the first key while
you press the second key. For ALT+W, hold down the ALT key
while you press the W key.

&
l
a

Monospace font
(quotation marks)

n
r
te

. . . (ellipses)

In

{ } (curly braces)

e
l
c

ra

Indicates a PeopleCode program or other code example.


Indicate lesson and chapter titles in cross-references and words that
are used differently from their intended meanings.
Indicate that the preceding item or series can be repeated any
number of times in PeopleCode syntax.
Indicate a choice between two options in PeopleCode syntax.
Options are separated by a pipe ( | ).

[ ] (square brackets)

Indicate optional items in PeopleCode syntax.

& (ampersand)

When placed before a parameter in PeopleCode syntax, an


ampersand indicates that the parameter is an already instantiated
object.

PeopleSoft Proprietary and Confidential

Ampersands also precede all PeopleCode variables.

PeopleCode

Preface

Visual Cues
Training courses contain the following visual cues.
Notes
Notes indicate information that you should pay particular attention to as you work with
the PeopleSoft system.
Note. Example of a note.
If the note is preceded by Important!, the note is crucial and includes information that
concerns what you must do for the system to function properly.
Important! Example of an important note.
Warnings
Warnings indicate crucial configuration considerations. Pay close attention to warning
messages.
Warning! Example of a warning.
Cross-References
Training guides provide cross-references either under the heading See Also or on a
separate line preceded by the word See. Cross-references lead to other documents, such
as PeopleBooks, that are pertinent to the immediately preceding documentation.

y
l
n

O
e

Example:

I
A

Example of cross-reference to a PeopleBook

Related Documentation

&
l
a

s
U

PeopleSoft applications are documented in PeopleBooks, which are delivered on the


PeopleBooks CD-ROM. You can also order printed, bound versions of PeopleBooks
through the Documentation section of the PeopleSoft Customer Connection website. You
can find updates and additional documentation for each release on the PeopleSoft
Customer Connection website.

n
r
te

n
I
e

See Also

cl

PeopleSoft Customer Connection, http://www.peoplesoft.com/corp/en/login.asp

a
r
O
vi

PeopleSoft Proprietary and Confidential

Lesson 1

Course Overview
This lesson has no activities.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

Course Overview

Lesson 1

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
2

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 2

Technology Overview
This lesson has no activities.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

Technology Overview

Lesson 2

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
4

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 3

Using PeopleCode Development


Tools

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

Using PeopleCode Development Tools

Activity 1:

Lesson 3

Reviewing the Application Development Process


In this activity, you will review the activity overview and review the eight steps of
application development using the Training Tasks application as an example.
See PeopleCode: Activity Guide, Using PeopleCode Development Tools, Activity 1:
Reviewing the Application Development Process.

Slide 23 _______________________________________________________________________________________________________

Activity Overview
In this activity, you will review the eight steps of application development, looking at
specific examples of how those steps were implemented to create the Training Tasks
application. In the process, you will consider how PeopleCode can be used to enhance
and complete the application.

Reviewing the Application Development Process


The eight steps are application development are:
1. Plan the application.
2. Define new fields and translate values.

y
l
n

3. Create record definitions.

O
e

4. Build Application Data tables.


5. Create the page definition.
6. Define the component.
7. Register the component.
8. Test.

&
l
a

Step 1: Planning the Application

I
A

s
U

n
r
te

This is probably the most difficult step in the entire process. Fortunately, our application
has been designed for us.

n
I
e

1. In Application Designer, open the PSU_TASKS project. This will make accessing
the objects easier as we discuss them.

cl

a
r
O

2. Select Tools, Options and select the Insert definition into project when definition is
modified and saved radio button and the Reload last project at startup checkbox.

Step 2: Creating Fields


1. Launch Application Designer.
a. Select Start, Programs, PeopleTools 8.44, Application Designer.

PeopleSoft Proprietary and Confidential

Lesson 3

Using PeopleCode Development Tools

b. Verify that your connection type is Application Server.


c. Select your database.
In the Central Training Environment (CTE) your database name will end in the
last two digits of your student ID. For instance, if your student ID is STA107,
then your database name might be T1B84407.
d. For User ID, enter PTCODE.
e. For password, enter PTCODE.
2. In the project workspace, expand the Fields folder.
3. Open the field TASK_STATUS by double-clicking it.
Field characteristics are global and are defined on the field definition, not on the
record definition. Change any field characteristic, and it will automatically be
changed in every record in which that field is used.
4. Select the Properties button to look at the fields translate values.
Step 3: Creating Records
1. Open the PSU_TASK_RSRC record definition.
2. Notice that the default display is the Field Display.

y
l
n

3. Select the Use Display button on the toolbar.


4. Double-click RESOURCE_NAME. Notice the default.
5. Double-click INSTRUCTOR.

s
U

6. Open the PSU_TASK_EFFORT record definition.

I
A

Step 4: Building the SQL Table

O
e

This is the most frequently forgotten step! Fortunately we dont need to build any tables.

&
l
a

Step 5: Creating Pages

1. Open the page PSU_TASK_RESOURCES.

n
r
te

2. Select the Order tab. Notice the Allow Deferred Processing column. Even if its
checked here, deferred processing must be enabled at the component level.

n
I
e

Step 6: Creating Components

l
c
a

1. Open the component PSU_TASK_RESOURCES.

r
O

2. Open the component properties. (You need to be on the components Definition tab,
not the Structure tab, to open properties.)
3. Select the Internet tab. Notice the Processing Mode choices: Deferred and Interactive.
Well spend more time on deferred processing later.
4. Close the Properties.

PeopleSoft Proprietary and Confidential

Using PeopleCode Development Tools

Lesson 3

5. Look at the Structure tab. Note the hierarchy of scrolls, records, and fields.
Step 7: Registering Components
The Component Registration Wizard attaches components to menu definitions, assigns
security access for users, and places navigational links in the registry. You wont need to
use the Component Registration Wizard in this course.
Step 8: Testing
1. Launch Internet Explorer.
a. For User ID, enter PTCODE.
b. For password, enter PTCODE.
2. Select Set Up Training, Training Tasks, Task Table to access the Tasks component.
3. Select Set Up Training, Training Tasks, Task Resources and Efforts to access the
Task Resources component.
4. Make sure to test by trying everything that a user can do in these components. For
instance:

Add a new task.

Associate resources and efforts to the new task, including insertions and deletions
in both scrolls.

Check prompts, defaults, etc.

Verify that rows have been written to the appropriate database tables.

y
l
n

This concludes the activity. Do not continue.

I
A

&
l
a

O
e

s
U

n
r
te

n
I
e

l
c
a

r
O
8

PeopleSoft Proprietary and Confidential

Lesson 3

Using PeopleCode Development Tools

Activity 2:

Using the PeopleCode Editor


In this activity, you will review the activity overview and experiment with several
features of the PeopleCode Editor.
See PeopleCode: Activity Guide, Using PeopleCode Development Tools, Activity 2:
Using the PeopleCode Editor.

Slide 32 _______________________________________________________________________________________________________

Using the PeopleCode Editor


You launch the PeopleCode editor by opening a PeopleCode program.
1. Open the PeopleCode program on the record field
PSU_STUDENT_TBL.SAME_ADDR_CUSTOMER.FIELDCHANGE.
Use any of the techniques you have learned to open the program in the PeopleCode
Editor.
2. Note that the text is color coded.
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.

y
l
n

O
e

3. Select the left drop-down list.

I
A

s
U

Notice that it shows the current field. Fields that have PeopleCode display in bold
type.
4. Select the right drop-down list.

&
l
a

Notice that it displays the current PeopleCode event.


Selecting it allows you to change events. Events with PeopleCode programs will
display in bold type.

n
r
te

5. Choose the field STUDENT_NAME and the event FieldEdit.

n
I
e

cl

ra

The larger text editor portion behaves like a standard text editor.

6. Enter the following text into the text editor, exactly as shown:
If ^ = student_id then warning "Student name equals student id.";

7. Save.
When you save or select Validate Syntax, the PeopleCode Editor checks syntax and
automatically formats the code.

PeopleSoft Proprietary and Confidential

Using PeopleCode Development Tools

Lesson 3

8. Did you get an error?


Add the following to the end of the line:
End-if;

9. Save again.
Notice the following features of the PeopleCode Editor:

If the editor encounters a caret (^) it replaces it with the current field name.

If the editor encounters a field name, it checks to see whether the field belongs to
the current record definition. If it does, it prepends the record name.

If the name doesnt exist, Validate Syntax displays a message in the Validate
pane but does not generate an error.

The editor capitalizes PeopleCode functions and constructs, puts keywords and
definition names in all caps and matches the case of all variables to the first
occurrence.

Text in quoted literals is ignored.

Validate Syntax checks for auto-declared variables and displays a message in the
Validate pane.

Cut, copy, paste, and undo are available, as in other text editors.

The PeopleCode definition is not saved with the record definition. It is stored in
other PeopleTools tables.

10. Position your cursor in the word Warning and press F1.

y
l
n

O
e

s
U

The PeopleCode PeopleBook opens to the Warning function.

I
A

11. Position your cursor in the word PSU_STUDENT_TBL.

Right-click and choose view definition.

&
l
a

You can view any definition, or the PeopleCode associated with a definition, by
right-clicking the definition name in a program.

n
r
te

12. If a user-defined function is referenced in a program, you can open that program by
right-clicking in the function name and selecting View Function.

n
I
e

13. The PeopleCode Editor supports drag and drop. Try dragging the following from the
project view into the editor pane (do not save):

cl

a
r
O
10

A record definition.

A record field (a field name within a record definition).

A component definition.

You can also drag and drop from a definition that is open in the definition workspace
and from one PeopleCode program to another.

PeopleSoft Proprietary and Confidential

Lesson 3

Using PeopleCode Development Tools

14. Navigate to the Z:\<Student ID>\temp\ directory, where <Student ID> is your CTE
student ID (for example, Z:\STA107\temp\).
a. Locate the file with the name PPCMMDDYY_HHMMSS.txt, where MMDDYY is
todays date and HHMMSS is the time the file was generated.
b. Double-click the file to open it in Notepad.
This is your PeopleCode AutoSave file. The PeopleCode editor automatically backs
up every keystroke between saves.
15. You can modify the font and colors used in the PeopleCode Editor.
a. Return to Application Designer.
b. Select Edit, Display Font and Colors
This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

11

Using PeopleCode Development Tools

Activity 3:

Lesson 3

Debugging a PeopleCode Program


In this activity, you will review the activity overview and investigate the features of the
PeopleCode debugger.
See PeopleCode: Activity Guide, Using PeopleCode Development Tools, Activity 3:
Debugging a PeopleCode Program.

Slide 34 _______________________________________________________________________________________________________

Activity Overview
In this activity, you will open the PeopleCode program at
ORDER_LINE_NBR.RowInsert on PSU_PO_DTL. You will set a breakpoint in the
program and run the application until it hits the breakpoint. Then you will explore the
types of information and options available to you through the Debugger.

Debugging a PeopleCode Program


1. In this activity, you will:Open a PeopleCode program.
2. Start the PeopleCode Debugger.
3. Set a visible breakpoint.

y
l
n

4. View values using Hover Inspect.

O
e

5. View values in the variables panes.


6. Look at the Debug Log Options.
7. Exit PeopleCode Debugger.
Opening a PeopleCode Program to Debug

I
A

s
U

1. Maximize your Application Designer window and close the Output Window (View,
Output Window) to make more room for your Debugger panes.

&
l
a

2. In Application Designer, open the record PSU_PO_DTL.

n
r
te

3. Open the program for ORDER_LINE_NBR.RowInsert.

n
I
e

4. Verify that you have the correct event: RowInsert, not RowDelete.
5. Close your Output pane (ALT+1) to make more room.

l
c
a

Starting the PeopleCode Debugger

r
O

12

1. From the menu, choose Debug, Enter Debug Mode.


2. The Local Variables watch window opens. If there are PeopleCode programs that had
breakpoints set from a previous debugging session, they are opened as well, and the
breakpoints are restored.

PeopleSoft Proprietary and Confidential

Lesson 3

Using PeopleCode Development Tools

3. Choose Debug, View Component Buffers. The Component Buffers pane opens.
Setting Visible Breakpoints
The Debugger supports visual indicators that signify breakpoint locations.
1. Place your cursor on the fourth line of code
If &LINE > &MAXLINE Then

and select Debug, Toggle Break at Cursor.


A red dot appears in the gutter beside the line of code.
2. To test, in the browser navigate to the Purchase Orders page.
Select Purchasing, Maintain Purchase Orders.
3. Select Order Number 00000029.
4. Position your cursor on the second line and insert a row (+).
5. Return to Application Designer. Notice the green arrow that marks the current
PeopleCode statement.
Viewing Values Using Hover Inspect
You can position the cursor (hover) over variables in the PeopleCode Editor to see their
current value.

y
l
n

Hover over &I and hold it until you see a pop-up containing the value of the variable.

O
e

You can also hover inspect field names to see the current value of the field.
Viewing Values in the Variables Panes

I
A

s
U

By default, the Local Variables pane appears with the debugger. This shows the values of
the variables and the properties of objects. You can expand objects here to view more
details about them.

&
l
a

You can also open panes for global variables, component variables, and function
parameters.

n
r
te

1. Press F8 to step to the next line of code.


The arrow that shows the current line of execution will move to the next line.
Continue to step through the code and notice how the variables change as you loop
through the rows in the component.

n
I
e

cl

a
r
O

2. Look at the component buffers window. This window gives you a view of all the data
in the component buffer.
Drill down until you see the values for the fields on the page.

Warning! Dont drill down on ParentRowset and ParentRow. You can end up in an
endless loop.

PeopleSoft Proprietary and Confidential

13

Using PeopleCode Development Tools

Lesson 3

Creating a Debug Log


You can output a debug log to the Application Designer PeopleCode Log output pane.
Select Debug, Options, Log Options
Note the checkboxes available for various options. You can also choose to save your
debug log. Be aware that logging will have a severe effect on performance.
Exiting PeopleCode Debugger
You should clean up before you exit the debugger.
1. Before exiting the Debugger it is good practice to clear your breakpoints. Go to
Debug, Edit Breakpoints and click the Remove All push button.
2. Select Debug, Abort Running Program.
3. Select Debug, Exit Debug Mode.
4. Window, Close All.
This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
14

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component


Processor

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

15

Describing the Component Processor

Activity 4:

Lesson 4

Watching the Search Events Run


In this activity, you will review the activity overview and place WinMessages in
SearchInit and SearchSave so that you can see exactly when those events run in the
Component Processor flow.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 4:
Watching the Search Events Run.

Slide 53 _______________________________________________________________________________________________________

Activity Overview
By placing a WinMessage in an event, you can see exactly when that event runs. In this
activity, you will place a WinMessage in SearchSave and SearchInit.

Watching the Search Events Run


To place WinMessages in SearchSave and SearchInit:
1. In PeopleSoft Application Designer, open the PSU_INSTR component definition.
2. From the left drop-down list, select PSU_INSTR_TBL (record).

y
l
n

3. From the right drop-down list, select SearchInit.


4. Enter the following code:

O
e

Component Integer &C;


&C = &C + 1;

s
U

WinMessage("SearchInit on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C);

I
A

5. From the right drop-down list, select SearchSave.


6. Enter the following code:

&
l
a

Component Integer &C;


&C = &C + 1;

n
r
te

WinMessage("SearchSave on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C);

n
I
e

7. Click the Save button.


8. Select Window, Close All.

l
c
a

r
O

9. In the PeopleSoft Internet Architecture, select Instructors, Professional Details.


The following message appears
SearchInit on COMPONENT.PSU_INSTR, PSU_INSTR_TBL <Instructor> C = 1
10. Click OK.

16

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component Processor

The search page for Instructor, Professional Details appears.


11. For Instructor, enter JEG and then click the Search button.
The following message appears:
SearchSave on COMPONENT.PSU_INSTR, PSU_INSTR_TBL <Instructor> C =
2
12. Click OK.
The Instructor, Professional Details page appears.
This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

17

Describing the Component Processor

Activity 5:

Lesson 4

Watching the Component Build Events Run


In this activity, you will review the activity overview and place WinMessages in PreBuild
and RowInit so that you can see exactly when those events run in the Component
Processor flow.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 5:
Watching the Component Build Events Run.

Slide 55 _______________________________________________________________________________________________________

Activity Overview
By placing a WinMessage in an event, you can see exactly when that event runs.
In this activity you will place WinMessages in PreBuild and RowInit.

Watching the Component Build Events Run


To watch the component build events run:
1. In PeopleSoft Application Designer, open the PeopleCode Editor for the
PSU_INSTR component definition.

y
l
n

2. From the left drop-down list, select PSU_INSTR_TBL (record).


3. From the right drop-down list, select RowInit.
4. Enter the following code:
Component Integer &C;

I
A

&C = &C + 1;

O
e

s
U

WinMessage("RowInit on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C, 0);

&
l
a

5. From the left drop-down list, select PSU_INSTR.GBL (component)


6. From the right drop-down list, select PreBuild.

n
r
te

7. Enter the following code:


Component Integer &C;

n
I
e

&C = &C + 1;

l
c
a

r
O
18

WinMessage("PreBuild on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C, 0);

8. Click the Save button.


9. Select Window, Close All.
10. If you have the Training application open in PeopleSoft Internet Architecture, log out
and log in again.

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component Processor

Because you have changed the PeopleCode, you need to refresh the cache.
11. In the PeopleSoft Internet Architecture, select Instructors, Professional Details.
12. Select the Correct History check box.
13. Select instructor JGY (Joe Young).
14. Observe the order in which the messages are displayed, and how often.
This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

19

Describing the Component Processor

Activity 6:

Lesson 4

Watching the Row Action Events Run


In this activity, you will review the activity overview and place a WinMessage in
RowInsert so that you can see exactly when this event runs in the Component Processor
flow.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 6:
Watching the Row Action Events Run.

Slide 58 _______________________________________________________________________________________________________

Activity Overview
By placing a WinMessage in an event, you can see exactly when that event runs.
In this activity, you will place a WinMessage in RowInsert.

Watching the Row Action Events Run


To watch the row action events run:
1. In PeopleSoft Application Designer, open the PeopleCode Editor for the
PSU_INSTR component definition.

y
l
n

2. From the left drop-down list, select PSU_INSTR_TBL (record).


3. From the right drop-down list, select RowInsert.
4. Enter the following code:
Component Integer &C;

I
A

&C = &C + 1;

O
e

s
U

WinMessage("RowInsert on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C, 0);

&
l
a

5. Click the Save button.

6. Select Window, Close All.

n
r
te

7. If you have the Training application open in PeopleSoft Internet Architecture, log out
and log in again.

n
I
e

Because you have changed the PeopleCode, you need to refresh the cache.

l
c
a

8. In PeopleSoft Internet Architecture, select Instructors, Professional Details.

r
O

9. Select the Correct History check box.


10. Select the instructor JGY (Joe Young).
11. Click the + button at level 1 (Instructor Information) to insert a new level 1 row.
12. Observe which events run.

20

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component Processor

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

21

Describing the Component Processor

Activity 7:

Lesson 4

Watching the Save Action Events Run


In this activity, you will review the activity overview and place a WinMessage in
SaveEdit so that you can see exactly when this event runs in the Component Processor
flow.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 7:
Watching the Save Action Events Run.

Slide 60 _______________________________________________________________________________________________________

Activity Overview
In this activity, you will place a WinMessage in SaveEdit.

Watching the Save Action Events Run


To watch the save action events run:
1. In PeopleSoft Application Designer, access the PSU_INSTR component definition.
2. Open the PeopleCode Editor.
3. From the left drop-down list, select PSU_INSTR_TBL (record).

y
l
n

4. From the right drop-down list, select SaveEdit.

O
e

5. Enter the following code:


Component Integer &C;
&C = &C + 1;

I
A

s
U

WinMessage("SaveEdit on COMPONENT.PSU_INSTR, PSU_INSTR_TBL " |


PSU_INSTR_TBL.INSTRUCTOR | " C = " | &C, 0);

6. Click the Save button.

&
l
a

7. Select Window, Close All.

8. If you have the Training application open in PeopleSoft Internet Architecture, log out
and log in again to refresh the cache.

n
r
te

9. In PeopleSoft Internet Architecture, select Instructors, Professional Details.

n
I
e

10. Select the Correct History check box.

cl

11. Select instructor JGY (Joe Young).

ra

12. Make a change to the page. (Give Joe a middle initial.)


13. Click the Save button.
14. Observe the displayed messages to determine which events run.
This concludes the activity. Do not continue.

22

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component Processor

Activity 8:

Examining Deferred Processing


In this activity, you will review the activity overview and look at the settings to control
deferred processing for the component, the page, and the field.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 8:
Examining Deferred Processing.

Slide 66 _______________________________________________________________________________________________________

Activity Overview
In this activity, you will look at the settings on component definitions, page definitions,
and page field properties that control deferred processing.

Examining Deferred Processing


At the component level, the processing mode is set in the Component Properties dialog
box, on the Internet tab. By default, under Processing Mode, the Deferred radio button is
selected, meaning that deferred processing is on.
To examine deferred processing:
1. In PeopleSoft Application Designer, open the PSU_TASK_RESOURCES.GBL
component.
2. Access the component properties and select the Internet tab.
3. In the Processing Mode group box:

O
e

s
U

To turn deferred processing off, select Interactive.

To turn deferred processing on, select Deferred.

I
A

y
l
n

Accept the default for this component, Deferred.

&
l
a

4. In the Allow Expert Entry check box:

Select Allow Expert Entry to enable the Allow Expert Entry check box on the
component.

Enable Expert Entry must also be selected for the user profile in Security
(PeopleTools, Security, User Profiles, User Profiles, General).

n
r
te

n
I
e

l
c
a

Note. Expert Entry is only meaningful if the component is in interactive mode. If the
component is in deferred mode, the Expert Entry checkbox will have no effect.

r
O

5. Select the Refresh check box in the Toolbar group box.


When the Refresh check box is selected, a Refresh button is displayed in the
component toolbar that allows the user to force a trip to the server.

PeopleSoft Proprietary and Confidential

23

Describing the Component Processor

Lesson 4

Users can always press ALT-0 to force a server trip, even if the Refresh button is not
displayed.
6. Open the PSU_TASK_RESOURCES page.
7. Access the Page Properties, Use tab.
Notice that the Allow Deferred Processing check box is selected.
8. Click the Cancel button.
9. From the PSU_TASK_RESOURCES page, open the Instructor page field and select
the Use tab.
Notice that the Allow Deferred Processing check box is selected.
10. Clear the Allow Deferred Processing check box to make this field interactive and
then click the OK button.
11. Select the Order tab on the PSU_TASK_RESOURCES page.
12. Scroll to the far right.
Notice that the check boxes for Allow Deferred Processing are display only and
cannot be changed here. Also notice that the check box for the INSTRUCTOR field
is cleared.
13. Click the Save button.

y
l
n

This concludes the activity. Do not continue.

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
24

PeopleSoft Proprietary and Confidential

Lesson 4

Describing the Component Processor

Activity 9:

Choosing the Right Events


In this activity, you will review the activity overview and choose the correct events in
which to place PeopleCode to enforce three business rules.
See PeopleCode: Activity Guide, Describing the Component Processor, Activity 9:
Choosing the Right Events.

Slide 67 _______________________________________________________________________________________________________

Activity Overview
Before beginning any PeopleCode customization, ask these three questions:
1. WHEN (Event)?
When should the PeopleCode be performed? In other words, which PeopleCode
event should be used? Sometimes more than one is required.
2. WHERE (Definition/Field)?
Where should the PeopleCode programs be attached? Depending on where the
PeopleCode is placed, processing may be affected.
3. WHAT (Syntax)?
What will the PeopleCode look like? Notice that this is the last step. Once the first
two questions have been answered, the syntax is usually fairly straightforward.

y
l
n

In this activity, you will write PeopleCode programs to address three business rules. The
code for these programs is straightforward. The greater challenge will be choosing the
correct event for each program. Keep the three questions in mind while working on the
following customizations:

O
e

s
U

1. On the Task Resources page, make sure that a resource is not available more than
100 percent of the time.

I
A

2. Make sure that a resource cannot be deleted from the Task Resources page if the
resource has finished the task.

&
l
a

3. On the Tasks page, if a start date and an end date have been entered, make sure that
the end date does not precede the start date.

n
r
te

Choosing the Right Events

n
I
e

Following each activity task is a PeopleCode program that meets the requirements of the
activity.

l
c
a

r
O

1. On the Task Resources page, make sure that a resource is not available more than
100 percent of the time.
Note. Because the component is in deferred mode, the Component Processor may
not recognize that PCT_AVAILABLE has been changed until the next server trip.
You need to turn off deferred processing for PCT_AVAILABLE.

PeopleSoft Proprietary and Confidential

25

Describing the Component Processor

Lesson 4

To turn off deferred processing for PCT_AVAILABLE:


a. Open the PSU_TASK_RESOURCES page definition.
b. View the page field properties for PCT_AVAILABLE.
c. Access the Use tab.
d. Clear the Allow Deferred Processing check box.
e. Click OK.
f.

Click the Save button.

[PSU_TASK_RSRC.PCT_AVAILABLE-FieldEdit]
/* UniqueID---------------------------------*/
If PSU_TASK_RSRC.PCT_AVAILABLE > 100 Then
Error "Resource cannot be available more than 100%.";
End-If;

2. Make sure a resource cannot be deleted from the Task Resources page if the resource
has finished the task.
Note. Because the component is in deferred mode, the Component Processor may
not recognize that COMPLETED_FLAG has been checked until the next server trip.
If you change the status of COMPLETED_FLAG to test RowDelete, save before
deleting a row.

y
l
n

O
e

[PSU_TASK_RSRC.COMPLETED_FLAG-RowDelete]
/* UniqueID-----------------------------------*/

s
U

If PSU_TASK_RSRC.COMPLETED_FLAG = "Y" Then

Error "Resource cannot be deleted if finished with the task.";

I
A

End-If;

3. On the Tasks page, if a start date and an end date have been entered, make sure that
the end date does not precede the start date.

&
l
a

[PSU_TASK_TBL.START_DT-SaveEdit]

/* UniqueID-----------------------------------*/

n
r
te

If All(PSU_TASK_TBL.START_DT, PSU_TASK_TBL.END_DT) And


PSU_TASK_TBL.START_DT > PSU_TASK_TBL.END_DT Then
Error "Start Date must precede End Date";

n
I
e

End-If;

cl

This concludes the activity. Do not continue.

a
r
O
26

PeopleSoft Proprietary and Confidential

Lesson 5

Writing PeopleCode Programs


This lesson has no activities.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

27

Writing PeopleCode Programs

Lesson 5

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
28

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 6

Understanding PeopleCode
Events

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

29

Understanding PeopleCode Events

Activity 10:

Lesson 6

Using SearchInit to control the Search Page


In this activity, you will review the activity overview and observe how the
SetSearchDialogBehavior function can be used to bypass the search page.
See PeopleCode: Activity Guide, Understanding PeopleCode Events, Activity 10:
Using SearchInit to control the search page.

Slide 95 _______________________________________________________________________________________________________

Activity Overview
In this activity, you will observe how the SetSearchDialogBehavior function is used to
bypass the search page.

Using SearchInit to Control the Search Page


Perform the following steps:
1. Select Change My Password to access the Change Password page.
2. Notice that you are taken directly to the Change Password page with the user ID
PTCODE.

y
l
n

3. In Application Designer open the record definition PSUSRSELF_SRCH and access


the SearchInit program on the field OPRID.

O
e

4. Add a REM statement in front of the line of the line SetSearchDialogBehavior(0).


5. Save your program.

s
U

6. Access the Change My Password page again. Notice that now you are taken to the
search page, and the User ID field is populated with PTCODE.

I
A

7. Compare your Change Password page with the following results.

&
l
a

Results

n
r
te

n
I
e

l
c
a

r
O

Change Password search page

30

PeopleSoft Proprietary and Confidential

Lesson 6

Understanding PeopleCode Events

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

31

Understanding PeopleCode Events

Activity 11:

Lesson 6

Synchronizing the Student Table with the Customer Table


In this activity, you will review the activity overview and look at how PeopleCode is used
to synchronize the Student Table and the Customer Table.
See PeopleCode: Activity Guide, Understanding PeopleCode Events, Activity 11:
Synchronizing the Student Table with the Customer Table.

Slide 116 ______________________________________________________________________________________________________

Activity Overview
You have seen RowInit and FieldChange programs that enable or disable fields on the
Student Table based on the value of the Same address as Customer checkbox on the
Students, Personal Details page.
You also saw that the FieldChange program populates the Students, Personal Details
page with values from the Customer Table if a user selects the Same address as Customer
checkbox.
The purpose of these programs is to maintain data integrity. If a student is meant to have
the same address as their employer (our customer), then PeopleCode is needed to prevent
a user from making any changes that will break that relationship.

y
l
n

If any address data in the Customer Table changes, the system needs to update any
students related to that customer to reflect the new information. As you saw, a
SavePostChange program is used for that purpose.

O
e

Synchronizing the Student Table with the Customer Table


In this activity you will:

I
A

s
U

1. Look at RowInit PeopleCode that is used to synchronize the Student Table and the
Customer Table.

2. Look at FieldChange PeopleCode that is used to synchronize the Student Table and
the Customer Table.

&
l
a

3. Observe how SavePostChange PeopleCode is used to synchronize the Student Table


and the Customer Table.

n
r
te

Looking at how RowInit PeopleCode synchronizes the Student Table and the Customer Table.

n
I
e

In this section you will create a search list with all the students who work for customer
XYZ and use the Next in List button to look at each student so you can observe the effect
of the Same address as Customer button.

l
c
a

r
O

1. Create a search list with all the students who work for customer XYZ.
a. Select Students, Personal Information.
b. On the search page, enter XYZ in the Customer field.

32

PeopleSoft Proprietary and Confidential

Lesson 6

Understanding PeopleCode Events

c. Select Search.
d. Select the first student link, which is Mark Larsen.
2. Use the Next in List button to look at each student.
3. Observe the relationship between the Same address as Customer checkbox and the
students address fields.

If the Same address as Customer checkbox is selected, the address fields are
disabled and cannot be changed.

If the Same address as Customer checkbox is cleared, the address fields are
enabled and the values can be changed.

4. Look at the RowInit program that accomplished this:


[PSU_STUDENT_TBL.SAME_ADDR_CUSTOMER.RowInit]
* 01/14/02 PSU EdDev */
/* Declare the record object */
Local Record &PSU_Student_Tbl;
/* Instantiate the record object */
&PSU_Student_Tbl = GetRecord(Record.PSU_STUDENT_TBL);

y
l
n

/* We could also create an object for the PSU_CUST_TBL record, but it is


not necessary and would only be extra code. */

O
e

If &PSU_Student_Tbl.SAME_ADDR_CUSTOMER.Value = "Y" Then


&PSU_Student_Tbl.STREET1.Enabled = False;
&PSU_Student_Tbl.CITY.Enabled = False;

s
U

&PSU_Student_Tbl.STATE.Enabled = False;

I
A

&PSU_Student_Tbl.ZIP.Enabled = False;

&PSU_Student_Tbl.COUNTRY.Enabled = False;

&PSU_Student_Tbl.PHONE.Enabled = False;

&
l
a

End-If;

Looking at how FieldChange PeopleCode synchronizes the Student Table and the Customer
Table.

n
r
te

In this section you will change the Same address as Customer checkbox, which will cause
the FieldChange program associated with that field to execute, then observe the effects of
that FieldChange program.

n
I
e

cl

1. Access the Personal Details page for Mark Larsen.

ra

You can either use the Return to Search push button and select Mark Larsen or select
the Previous in List push button until you reach Mark Larsen.

2. Click on the Same address as Customer checkbox to clear it.


Notice that the address fields are enabled.

PeopleSoft Proprietary and Confidential

33

Understanding PeopleCode Events

Lesson 6

3. Change Marks street address to One Larsen Way.


4. Select the Same address as Customer checkbox.
Notice the address fields are disabled .
What is Marks street address now?
5. Look at the FieldChange program that accomplished this:
[PSU_STUDENT_TBL.SAME_ADDR_CUSTOMER.FieldChange]
/* 01/14/02 PSU EdDev */
/* Declare the record object */
Local Record &PSU_Student_Tbl;
/* Instantiate the record object */
&PSU_Student_Tbl = GetRecord(Record.PSU_STUDENT_TBL);
/* We could also create an object for the PSU_CUST_TBL record, but it is
not necessary and would only be extra code. */
If &PSU_Student_Tbl.SAME_ADDR_CUSTOMER.Value = "Y" Then
&PSU_Student_Tbl.STREET1.Enabled = False;
&PSU_Student_Tbl.CITY.Enabled = False;
&PSU_Student_Tbl.STATE.Enabled = False;
&PSU_Student_Tbl.ZIP.Enabled = False;

y
l
n

&PSU_Student_Tbl.COUNTRY.Enabled = False;
&PSU_Student_Tbl.PHONE.Enabled = False;

O
e

&PSU_Student_Tbl.STREET1.Value = PSU_CUST_TBL.STREET1;
&PSU_Student_Tbl.CITY.Value = PSU_CUST_TBL.CITY;

&PSU_Student_Tbl.STATE.Value = PSU_CUST_TBL.STATE;

s
U

&PSU_Student_Tbl.ZIP.Value = PSU_CUST_TBL.ZIP;

I
A

&PSU_Student_Tbl.COUNTRY.Value = PSU_CUST_TBL.COUNTRY;
&PSU_Student_Tbl.PHONE.Value = PSU_CUST_TBL.PHONE;
Else

&PSU_Student_Tbl.STREET1.Enabled = True;

&
l
a

&PSU_Student_Tbl.CITY.Enabled = True;
&PSU_Student_Tbl.STATE.Enabled = True;
&PSU_Student_Tbl.ZIP.Enabled = True;

n
r
te

&PSU_Student_Tbl.COUNTRY.Enabled = True;
&PSU_Student_Tbl.PHONE.Enabled = True;

n
I
e
End-If;

6. Identify the section of code that updates the address fields when the Same Address as
Customer checkbox is selected.

l
c
a

r
O

Observing how SavePostChange PeopleCode synchronizes the Student Table and the
Customer Table.

34

In the previous walk-throughs you saw how PeopleCode on the Student Table kept data
on the Student Table synchronized. In this section you will observe how changes to the
Customer Table can trigger PeopleCode that will update the Student Table as needed.

PeopleSoft Proprietary and Confidential

Lesson 6

Understanding PeopleCode Events

1. Select Customers, General Information.


2. Access Customer XYZ.
3. Change the customers address to:
One PeopleSoft Way
Pleasanton, CA 90210
4. Save the component.
5. Once again, create a search list with students who work for customer XYZ (see
above).
Notice that the address has changed for each student that has Same address as
Customer selected.
6. Look at the PeopleCode program that accomplished this:
[PSU_CUST.GBL.SavePostChange]
If FieldChanged(PSU_CUST_TBL.STREET1) Or
FieldChanged(PSU_CUST_TBL.CITY) Or
FieldChanged(PSU_CUST_TBL.STATE) Or
FieldChanged(PSU_CUST_TBL.ZIP) Or
FieldChanged(PSU_CUST_TBL.COUNTRY) Or
FieldChanged(PSU_CUST_TBL.PHONE) Then
SQLExec("Update PS_PSU_STUDENT_TBL set STREET1 = :1, CITY = :2, STATE
= :3, ZIP = :4, COUNTRY = :5, PHONE = :6 Where CUSTOMER_ID = :7 and
SAME_ADDR_CUSTOMER = 'Y' ", PSU_CUST_TBL.STREET1, PSU_CUST_TBL.CITY,
PSU_CUST_TBL.STATE, PSU_CUST_TBL.ZIP, PSU_CUST_TBL.COUNTRY,
PSU_CUST_TBL.PHONE, PSU_CUST_TBL.CUSTOMER_ID);

y
l
n

O
e

End-If;

This concludes the activity. Do not continue.

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

35

Understanding PeopleCode Events

Lesson 6

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
36

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 7

Using PeopleCode Variables

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

37

Using PeopleCode Variables

Activity 12:

Lesson 7

Using Derived Work Fields


In this activity, you will review the activity overview and add derived/work fields to the
Training Tasks application to track effort to go and display a resource status.
See PeopleCode: Activity Guide, Using PeopleCode Variables, Activity 12: Using
Derived Work Fields.

Slide 136 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will use derived/work fields to calculate and display values that
would not normally be stored in the database.
1. Create an Effort to Go field for the Task Table Page.

Currently, PSU_TASK_TBL tracks the amount of total effort required and effort
spent for a task. Using these two fields, calculate the value of EFFORT_TO_GO
and display it on the PSU_TASK page.

Make sure to test the application thoroughly. Think of everything that could be
done by a user .

y
l
n

2. Display a resource status on the Task Resources page.

Assign a resource status to each of the resources working on a task. It should be


based on the percentage of time the resource has available to work on the task.
The chart below indicates the guidelines for assigning a resource status. Try
using an evaluate statement.

O
e

I
A

Percent Available

Resource Status

100%

Dedicated

50%99%

Semi-Dedicated

&
l
a

25%49%
below 25%

Part Time
Occasional

n
I
e

l
c
a

r
O

n
r
te

s
U

Test.

The description of the resource status should display on the page.


Test for different values in the Percent Available field.

Using Derived Work Fields


In this activity you will:

38

PeopleSoft Proprietary and Confidential

Lesson 7

Using PeopleCode Variables

1. Create an Effort to Go field for the Task Table page.


2. Display a resource status on the Task Resources page.
Creating an Effort to Go Field for the Task Table
Perform the following steps:
1. Create an EFFORT_TO GO field as signed number.
2. Create a record definition named DERIVED_TRAIN.
3. Add the EFFORT_TO_GO field to DERIVED_TRAIN.
Set the record type to Derived/Work. You dont need to build the table.
4. Put the DERIVED_TRAIN.EFFORT_TO_GO field on the PSU_TASK page.

Make it display-only.

In the page field properties, select the Display Zero checkbox or else a blank will
be displayed.

5. Make the fields EFFORT_SPENT and EFFORT_TOTAL interactive or display the


Refresh button on the page.
6. Add the following PeopleCode:

y
l
n

[PSU_TASK_TBL.EFFORT_SPENT-RowInit]
/* UniqueID-----------------------------------*/
DERIVED_TRAIN.EFFORT_TO_GO = PSU_TASK_TBL.EFFORT_TOTAL PSU_TASK_TBL.EFFORT_SPENT;
[PSU_TASK_TBL.EFFORT_SPENT-FieldChange]

s
U

/* UniqueID-----------------------------------*/

I
A

O
e

DERIVED_TRAIN.EFFORT_TO_GO = PSU_TASK_TBL.EFFORT_TOTAL PSU_TASK_TBL.EFFORT_SPENT;

[PSU_TASK_TBL.EFFORT_TOTAL-FieldChange]

&
l
a

/* UniqueID-----------------------------------*/
DERIVED_TRAIN.EFFORT_TO_GO = PSU_TASK_TBL.EFFORT_TOTAL PSU_TASK_TBL.EFFORT_SPENT;

n
r
te

7. Test.

n
I
e

Displaying a resource status on the Task Resources page


Perform the following steps:

l
c
a

r
O

1. Create a character field named RESOURCE_STATUS. Enter the appropriate


translate values.
2. Add RESOURCE_STATUS field to DERIVED_TRAIN. On the Record Field
Properties, Edits tab, set the Table Edit type to Translate Table.
3. Add DERIVED_TRAIN.RESOURCE_STATUS to the Task Resources page as a
dropdown list.

PeopleSoft Proprietary and Confidential

39

Using PeopleCode Variables

Lesson 7

4. In the page field properties, on the Record tab, select the radio button for Xlat Long.
5. Make the field display-only.
6. Make the field PCT_AVAILABLE interactive or display the Refresh button on the
page.
7. Add the following PeopleCode:
[PSU_TASK_RSRC.PCT_AVAILABLE-RowInit]
and
[PSU_TASK_RSRC.PCT_AVAILABLE-FieldChange]
/* UniqueID-----------------------------------*/
Evaluate PSU_TASK_RSRC.PCT_AVAILABLE
When = 0
DERIVED_TRAIN.RESOURCE_STATUS = "0";
Break;
When = 100
DERIVED_TRAIN.RESOURCE_STATUS = "4";
Break;
When >= 50
DERIVED_TRAIN.RESOURCE_STATUS = "3";

y
l
n

Break;
When >= 25
DERIVED_TRAIN.RESOURCE_STATUS = "2";

O
e

Break;
When-Other
DERIVED_TRAIN.RESOURCE_STATUS = "1";
End-Evaluate;

I
A

8. Test.

s
U

This concludes the activity. Do not continue.

&
l
a

n
r
te

n
I
e

l
c
a

r
O
40

PeopleSoft Proprietary and Confidential

Lesson 7

Using PeopleCode Variables

Activity 13:

Setting Up a Variable Prompt Table Edit


In this activity, you will review the activity overview and look at the steps that were
taken to set up a variable prompt table edit.
See PeopleCode: Activity Guide, Referencing User-Defined Variables in PeopleCode,
Activity 13: Setting up a Variable Prompt Table Edit.

Slide 138 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will look at the steps to set up a variable prompt table edit and look
specifically at how the variable prompt table edit was implemented for the Review
Details page.

Setting Up a Variable Prompt Table Edit


In this activity you will learn how to:
1. Determine whether to add a field to the DERIVED record.
2. Set the prompt table edit to %FieldName.

y
l
n

3. Add the DERIVED field to the page.


4. Possibly set the triggering field to Interactive Mode.

O
e

5. Populate the field DERIVED.FieldName using PeopleCode.


Determining Whether to Add a Field to the DERIVED Record

I
A

Open the record definition DERIVED.

s
U

The DERIVED record is a delivered record and already contains a number of fields.
Since it is a delivered record, you want to avoid adding fields, but you will probably find
what you need is already there. You cannot clone it, since the name must be DERIVED.

&
l
a

The first field in DERIVED is EDITTABLE. That works for most purposes. If you need
to put more than one variable prompt table field on a component, there are fields called
EDITTABLE2, EDITTABLE3, and so on.

n
r
te

n
I
e

Setting the Prompt Table Edit to %FieldName

l
c
a

In the record field properties of the field that has the prompt, set the prompt table edit to
%FieldName, where FieldName is a field on the derived/work record DERIVED.

r
O

If you use the DERIVED field EDITTABLE, in the record definition you would enter
%EDITTABLE as the prompt table name.
Open the record definition PSU_EMP_RVW_RVR.

PeopleSoft Proprietary and Confidential

Double-click the field REVIEWER_ID to access its record field properties

41

Using PeopleCode Variables

Lesson 7

Select the Edits tab.

Notice the Prompt Table name %EDITTABLE.

Adding the DERIVED Field to the Page


In order for PeopleCode to access the value in the field, it must be loaded into the
Component Buffer, which means it must be on the page. Put it at the same level as the
prompt table field. You will probably want to make it invisible.
1. Open the page definition PSU_EMP_REVIEW.
2. On the page definition, double-click the field Edit Table.

Notice the Record Name: DERIVED

Notice the Field Name EDITTABLE.

3. Click Cancel.
Setting the Triggering Field to Interactive Mode
If the variable prompt table is conditional based on an enabled field, you need to turn off
deferred processing for that field. Otherwise, the user prompt table may not change
before the user accesses the prompt.
1. On the page definition double-click the field Review Type.

y
l
n

2. Select the Use tab.

O
e

Notice that the Allow Deferred Processing checkbox is cleared. This field must be in
interactive mode in order for the FieldChange PeopleCode to execute when the field
is changed.
Populating the Field DERIVED.FieldName Using PeopleCode

I
A

s
U

Probably in some type of Evaluate or If statement, you will have a statement like this:

DERIVED.EDITTABLE = Record_Name;

&
l
a

Consider all the events in which your code needs to be placed. Probably PreBuild or
RowInit, and FieldChange.

n
r
te

1. Open the component definition PSU_EMP_REVIEW.


2. Select the Structure tab.

n
I
e

3. Right-click and choose View PeopleCode.

l
c
a

4. Select the program for PSU_EMP_RVW_RVR.RowInit.

r
O
42

Notice the code that populates the DERIVED.EDITTABLE field with the
appropriate value based on the value of the REVIEW_TYPE.

This concludes the activity. Do not continue.

PeopleSoft Proprietary and Confidential

Lesson 8

Using Built-In Functions

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

43

Using Built-In Functions

Activity 14:

Lesson 8

Using Built-In Functions


In this activity, you will review the activity overview and use built-in functions to
enhance the Training Tasks application.
See PeopleCode: Activity Guide, Using Built-In Functions, Activity 14: Using Built-In
Functions.

Slide 164 ______________________________________________________________________________________________________

Activity Overview
From now on, when displaying an error or warning message to the user, add the text to
the Message Catalog and retrieve it using a function such as MsgGet.
1. Warn the user that managerial approval must be obtained when attempting to modify
the task end date by more than three months.
2. On the Tasks page, issue a warning when the system date exceeds the start date and
the task effort spent equals zero. This scenario implies that the task should have
started, but hasn't yet because no effort has been recorded.

Using Built-In Functions

y
l
n

1. Warn the user that managerial approval must be obtained when attempting to modify
the task end date by more than three months.

Change the END_DT field to Interactive.

Add a message to the Message Catalog:

O
e

I
A

s
U

a. Select PeopleTools, Utilities, Administration, Message Catalog.


b. Click the Add A New Value tab.

c. For Message Set Number, enter 30420.

&
l
a

d. Click Add.

n
r
te

e. Enter the following information:


Page Element

Value or Status

Description

PeopleCode Course

e
l
c

In

Message Text

a
r
O

f.

Managerial approval must be obtained to modify


end date by more than 3 months

Save.

Add the following PeopleCode.


[PSU_TASK_TBL.END_DT-FieldEdit]

44

PeopleSoft Proprietary and Confidential

Lesson 8

Using Built-In Functions

/* UniqueID------------------------------------*/
Local date &Prior;
If None(PSU_TASK_TBL.END_DT) Then
/* Need to add a message to the Message Catalog for this to work */
Warning MsgGet(20000, 7, "MESSAGE NOT FOUND.");
Else
&Prior = PriorValue(PSU_TASK_TBL.END_DT);
If All(&Prior) Then
If PSU_TASK_TBL.END_DT > AddToDate(&Prior, 0, 3, 0) Or
PSU_TASK_TBL.END_DT < AddToDate(&Prior, 0, - 3, 0) Then
/*Need to add a message to the Message Catalog for this to work*/
Warning MsgGet(30420, 1, "MESSAGE NOT FOUND.");
End-If;
End-If;
End-If;

2. On the Tasks page, issue a warning when the system date exceeds the start date and
the task effort spent equals zero. This scenario implies that the task should have
started, but hasn't yet because no effort has been recorded.
Make sure this warning only happens when on the Tasks page.

Add a message to the Message Catalog:

y
l
n

a. Select PeopleTools, Utilities, Administration, Message Catalog.

O
e

b. For Message Set Number, enter 30420.


c. Click Search.
d. Enter the following information:

I
A

Page Element

s
U

Value or Status

Message Text

&
l
a

e. Save.

Start date has passed and no work has begun.

n
r
te

n
I
e

Add the following PeopleCode:

cl

ra

[PSU_TASK.GBL.PSU_TASK_TBL.SaveEdit]
/* UniqueID------------------------------------*/
If All(PSU_TASK_TBL.START_DT, PSU_TASK_TBL.EFFORT_TOTAL) Then

If (%Date > PSU_TASK_TBL.START_DT) And


None(PSU_TASK_TBL.EFFORT_SPENT)Then
/* Need to add a message to the Message Catalog for this to
work */
Warning MsgGet(30420, 2, "MESSAGE NOT FOUND.");
End-If;

PeopleSoft Proprietary and Confidential

45

Using Built-In Functions

Lesson 8

End-If;

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
46

PeopleSoft Proprietary and Confidential

Lesson 9

Writing PeopleCode Functions

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

47

Writing PeopleCode Functions

Activity 15:

Lesson 9

Writing Functions
In this activity, you will review the activity overview and write PeopleCode functions to
modularize five programs you wrote in earlier activities.
See PeopleCode: Activity Guide, Writing PeopleCode Functions, Activity 15: Writing
Functions.

Slide 174 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will convert five existing programs into functions.
1. On the Tasks page, in order to calculate the Effort to Go for a task, the same logic
was used in several different PeopleCode programs. Instead of using the same
program in different places, create an external PeopleCode function to perform this
logic. The function can then be called wherever the logic is needed.
2. On the Task Resources page, calculating the Resource Status based upon the percent
available also reused the same PeopleCode in different places. Create an external
PeopleCode function to perform this logic. Try to use a different method of writing
the function than you used above (for instance, no parameters, a different
combination of input/output parameters, or using Returns).

y
l
n

Writing Functions

O
e

Following each task description are PeopleCode programs that represent a possible
solution to the activity.

s
U

1. On the Tasks page, in order to calculate the Effort to Go for a task, the same logic
was used in several different PeopleCode programs. Instead of using the same
program in different places, create an external PeopleCode function to perform this
logic. The function can then be called wherever the logic is needed.

I
A

&
l
a

a. Create a new derived/work record named FUNCLIB_TRAIN.


b. Add the field EFFORT_TO_GO to the record.

n
r
te

c. Save.

d. Add the following PeopleCode:

n
I
e

[FUNCLIB_TRAIN.EFFORT_TO_GO-FieldFormula]

l
c
a

r
O

/* UniqueID-----------------------------------*/
Function Calc_Effort_ToGo()
DERIVED_TRAIN.EFFORT_TO_GO = PSU_TASK_TBL.EFFORT_TOTAL PSU_TASK_TBL.EFFORT_SPENT;
End-Function;

e. Comment out the existing code in the following programs and add the code
shown:

48

PeopleSoft Proprietary and Confidential

Lesson 9

Writing PeopleCode Functions

[PSU_TASK_TBL.EFFORT_SPENT-RowInit]
/* UniqueID-----------------------------------*/
Declare Function Calc_Effort_ToGo PeopleCode FUNCLIB_TRAIN.EFFORT_TO_GO
FieldFormula;
Calc_Effort_ToGo();
[PSU_TASK_TBL.EFFORT_SPENT-FieldChange]
/* UniqueID-----------------------------------*/
Declare Function Calc_Effort_ToGo PeopleCode FUNCLIB_TRAIN.EFFORT_TO_GO
FieldFormula;
Calc_Effort_ToGo();
[PSU_TASK_TBL.EFFORT_TOTAL-FieldChange]
/* UniqueID-----------------------------------*/
Declare Function calc_effort_togo PeopleCode
FUNCLIB_TRAIN.EFFORT_TO_GO FieldFormula;
Calc_Effort_ToGo();

2. On the Task Resources page, calculating the Resource Status based upon the percent
available also reused the same PeopleCode in different places. Create an external
PeopleCode function to perform this logic. Try to use a different method of writing
the function than you used above (for instance, no parameters, a different
combination of input/output parameters, or using Returns).

O
e

[FUNCLIB_TRAIN.RESOURCE_STATUS-FieldFormula]
/* UniqueID-----------------------------------*/

s
U

Function ResourceStatus(&PCT) Returns string


Evaluate &PCT

I
A

When = 0
Return "0";
When = 100
Return

&
l
a

"4";

When >= 50
Return

"3";

y
l
n

n
r
te

When >= 25
Return

n
I
e

"2";

When-Other
Return

cl

a
r
O

"1";

End-Evaluate;

End-Function;
[PSU_TASK_RSRC.PCT_AVAILABLE-RowInit]
/* UniqueID-----------------------------------*/
Declare Function ResourceStatus PeopleCode
FUNCLIB_TRAIN.RESOURCE_STATUS FieldFormula;

PeopleSoft Proprietary and Confidential

49

Writing PeopleCode Functions

Lesson 9

DERIVED_TRAIN.RESOURCE_STATUS =
ResourceStatus(PSU_TASK_RSRC.PCT_AVAILABLE);
[PSU_TASK_RSRC.PCT_AVAILABLE-FieldChange]
/* UniqueID------------------------------------*/
Declare Function ResourceStatus PeopleCode
FUNCLIB_TRAIN.RESOURCE_STATUS FieldFormula;
DERIVED_TRAIN.RESOURCE_STATUS =
ResourceStatus(PSU_TASK_RSRC.PCT_AVAILABLE);

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
50

PeopleSoft Proprietary and Confidential

Lesson 10

Explaining the Component Buffer

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

51

Explaining the Component Buffer

Activity 16:

Lesson 10

Determining the Contents of the Component Buffer


In this activity, you will review the activity overview and determine what fields and what
PeopleCode programs are loaded into the component buffer for the Course Enrollment
component.
See PeopleCode: Activity Guide, Understanding the Component Buffer, Activity 16:
Determining the Contents of the Component Buffer.

Slide 183 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will look at the record definition and page definition for the Course
Enrollment component and apply the rules of component buffer allocation to determine
what fields and what PeopleCode programs will be loaded into the buffer.

Determining the Contents of the Component Buffer


1. In the browser, select Courses, Course Enrollment.
2. Answer the following question:
Question

Answer

What fields are on the search page?

1.

y
l
n

2.

O
e

3.
4.

I
A

s
U

3. In Application Designer, open the record definition PSU_CRS_SESSN.


4. Answer the following questions:
Question

na

Which fields are search keys?

52

r
e
nt

Answer
1.
2.

Which fields are alternate search keys?

1.

I
e

2.

l
c
a

r
O

l&

5. In Application Designer, open the page definition PSU_CRS_ENROLL.


6. Select the Order tab.

PeopleSoft Proprietary and Confidential

Lesson 10

Explaining the Component Buffer

7. Answer the following questions:


Question

Answer

What is the primary record definition for level 0?


What is the primary record definition for level 1?

8. Refer to the page definition to complete the following table:


Level

Record

Field

Type

What loads?

PC?

y
l
n

O
e

I
A

&
l
a

s
U

This concludes the activity. Do not continue.

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

53

Explaining the Component Buffer

Lesson 10

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
54

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 11

Accessing Data in the Component


Buffer
This lesson has no activities.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

55

Accessing Data in the Component Buffer

Lesson 11

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
56

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 12

Programming With ObjectOriented PeopleCode

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

57

Programming With Object-Oriented PeopleCode

Activity 17:

Lesson 12

Using Object-Oriented Methods and Properties


In this activity, you will review the activity overview and use object-oriented PeopleCode
to implement enhancements to the Course Sessions and Task Resources applications.
See PeopleCode: Activity Guide, Programming With Object-Oriented PeopleCode,
Activity 17: Using Object-Oriented Methods and Properties.

Slide 210 ______________________________________________________________________________________________________

Activity Overview
Use object-oriented PeopleCode to complete the following tasks:
1. On the Course Sessions page, PeopleCode issues an error if the start date is greater
than the end date. Enhance your program so that the cursor moves to the Start Date
field when this error occurs. The program is on the component PSU_CRS_SESSN.
To access the Course Sessions page, select Courses, Define, Course Sessions. Select
Course Code 1001.
2. On the Task Resources page, make the Instructor and Resource Name fields work
properly together. If the instructor is changed, the resource name should change also.
If there is a value in the Instructor field, disable the Resource Name field.

Using Object-Oriented Methods and Properties

y
l
n

O
e

The PeopleCode for each task follows the task description.

s
U

1. On the Course Sessions page, PeopleCode issues an error if the start date is greater
than the end date. Enhance your program so that the cursor moves to the Start Date
field when this error occurs. The program is on the component PSU_CRS_SESSN.

I
A

[PSU_CRS_SESSN.GBL.PSU_CRS_SESSN-SaveEdit]

/* UniqueID------------------------------------*/

&
l
a

Local Field &StartDt;

If All(PSU_CRS_SESSN.START_DATE, PSU_CRS_SESSN.END_DATE) And

n
r
te

PSU_CRS_SESSN.START_DATE > PSU_CRS_SESSN.END_DATE Then


&StartDt = GetField(PSU_CRS_SESSN.START_DATE);

n
I
e

&StartDt.SetCursorPos(%Page);

l
c
a

r
O

Error MsgGet(1040, 3, "Message Not Found: Course Start Date must not
be later than End Date.", PSU_CRS_SESSN.START_DATE,
PSU_CRS_SESSN.END_DATE)
End-If;

2. On the Task Resources page, make the Instructor and Resource Name fields work
properly together. If the instructor is changed, the resource name should change also.
If there is a value in the Instructor field, disable the Resource Name field.
[PSU_TASK_RSRC.INSTRUCTOR -RowInit]
/* UniqueID------------------------------------*/

58

PeopleSoft Proprietary and Confidential

Lesson 12

Programming With Object-Oriented PeopleCode

If All(PSU_TASK_RSRC.INSTRUCTOR) Then
Local Field &Resource;
&Resource = GetField(PSU_TASK_RSRC.RESOURCE_NAME);
&Resource.Enabled = False;
End-If;
[PSU_TASK_RSRC.INSTRUCTOR-FieldChange]
/* UniqueID------------------------------------*/
Local Field &Resource;
&Resource = GetField(PSU_TASK_RSRC.RESOURCE_NAME);
&Resource.SetDefault();
If All(PSU_TASK_RSRC.INSTRUCTOR) Then
&Resource.Enabled = False;
Else
&Resource.Enabled = True;
End-If;

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

59

Programming With Object-Oriented PeopleCode

Lesson 12

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
60

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 13

Referencing Data in the


Component Buffer

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

61

Referencing Data in the Component Buffer

Activity 18:

Lesson 13

Stepping Through the Data Buffer


In this activity, you will review the activity overview and step through the process of
traversing the component buffer from level 0 to level 1 and identify the data that is
returned for each step.
See PeopleCode: Activity Guide, Referencing Data in the Component Buffer, Activity
18: Stepping Through the Data Buffer.

Slide 222 ______________________________________________________________________________________________________

Activity Overview
In this activity you will review the seven steps to traverse a data buffer from level 0 to
level 1 and answer some questions.

Stepping Through the Data Buffer


Before you look at the steps below, on your workstation access the Task Resources page.
The seven steps are:
Step 1. Declare data buffer objects.

y
l
n

Step 2. Get the level 0 rowset.


Step 3. Get the level 0 row.

O
e

Step 4. Get a level 1 rowset.


Step 5. Get a level 1 row.

I
A

Step 6. Get a level 1 record.


Step 7. Get a level 1 field.

&
l
a

Accessing the Task Resources page

s
U

1. Select Set Up Training, Training Tasks, Task Resources and Efforts.

n
r
te

2. Select Task 0001.

The table you will be working with below is a representation of the component buffer for
the Task Resources and Efforts component for Task 0001.

n
I
e

l
c
a

Step 1. Declaring data buffer objects

r
O

It is always good practice to declare variables and it is especially important to declare


objects.
Fill in the object types in the declaration statements below.
Local

62

&RS_Level0, &RS_Level1;

PeopleSoft Proprietary and Confidential

Lesson 13

Referencing Data in the Component Buffer

Local

&Row_Level0, &Row_Level1;

Local

&Rec_TaskRsrc;

Local

&Fld_PctAvail;

Step 2. Getting the level 0 rowset


Using the GetLevel0 function, instantiate the level 0 rowset.
&RS_LEVEL0

= GetLevel0();

Draw a box around the cells in the table below that represent the level 0 rowset
PSU_TASK_TBL

PSU_TASK_RSRC

DERIVED_TRAIN

PSU_TASK_EFFORT

Task

Descr

Resource
Name

Pct
Avail

Resource Status

Effort Date

Effort
Amount

0001

Tools I
Guide
Ed Kelly

50

Semi-Dedicated
11/16/01

7.0

11/15/01

8.0

11/14/01

6.0

y
l
n

11/13/01
Jim Gutenkauf

100

Dedicated

O
e

01/08/02

I
A

Step 3. Getting the level 0 row

&
l
a

s
U

6.0

9.5

01/07/02

10.0

01/05/02

12.0

Using the level 0 rowset object with the GetRow method, instantiate the level 0 row.
There is always exactly one row at level 0 of the component buffer, so the argument for
GetRow is always 1 to get the level 0 row.

n
r
te

&ROW_LEVEL0

n
I
e

= &RS_Level0.GetRow(1);

Draw a box around the cells in the table below that represent the level 0 row.

cl

a
r
O

PSU_TASK_TBL

PSU_TASK_RSRC

DERIVED_TRAIN

PSU_TASK_EFFORT

Task

Descr

Resource
Name

Pct
Avail

Resource Status

Effort Date

Effort
Amount

0001

Tools I
Guide
Ed Kelly

50

Semi-Dedicated
11/16/01

7.0

PeopleSoft Proprietary and Confidential

63

Referencing Data in the Component Buffer

Lesson 13

Jim Gutenkauf

100

11/15/01

8.0

11/14/01

6.0

11/13/01

6.0

01/08/02

9.5

01/07/02

10.0

01/05/02

12.0

Dedicated

Step 4. Getting a level 1 rowset


A row contains one or more records and zero or more child rowsets. In this case, the level
0 row contains one level 1 rowset. Since there could be more than one level 1 scroll, you
need to specify which scroll by name.
Using the level 0 row object with the GetRowSet method, specify the primary record of
the scroll.
&RS_LEVEL1

= &ROW_LEVEL0.GetRowSet(SCROLL.PSU_Task_RSRC);

Draw boxes around the cells in the table below that represents the level 1
PSU_Task_RSRC rowset.
PSU_TASK_RSRC

DERIVED_TRAIN

PSU_TASK_EFFORT

Task

Descr

Resource
Name

Pct
Avail

Resource Status

Effort Date

0001

Tools I
Guide
Ed Kelly

50

Semi-Dedicated

na

l&

Jim Gutenkauf

r
e
nt

I
e

l
c
a

r
O

y
l
n

PSU_TASK_TBL

100

I
A

O
e

s
U

Effort
Amount

11/16/01

7.0

11/15/01

8.0

11/14/01

6.0

11/13/01

6.0

01/08/02

9.5

01/07/02

10.0

01/05/02

12.0

Dedicated

Step 5. Getting a level 1 row.


A rowset contains one or more rows; this example has two. Usually, you wont know the
specific row number and will loop through the rowset using a variable, such as &I, to
access each row.
Using the Level 1 rowset object with the GetRow method, specify the row number.

64

PeopleSoft Proprietary and Confidential

Lesson 13

Referencing Data in the Component Buffer

&Row_Level1

= &RS_Level1.GetRow(2);

Draw a box around the cells in the table below that represent level 1, row 2.
PSU_TASK_TBL

PSU_TASK_RSRC

DERIVED_TRAIN

PSU_TASK_EFFORT

Task

Descr

Resource
Name

Pct
Avail

Resource Status

Effort Date

Effort
Amount

0001

Tools I
Guide
Ed Kelly

50

Semi-Dedicated
11/16/01

7.0

11/15/01

8.0

11/14/01

6.0

11/13/01

6.0

01/08/02

9.5

01/07/02

10.0

01/05/02

12.0

Jim Gutenkauf

100

Dedicated

Step 6. Getting a level 1 record.

y
l
n

A row object contains one or more records and may contain child rowsets. In this
example we want to get a record. Later, you will learn how to access the child rowset at
level 2.

O
e

s
U

Using the level 1 row object with the GetRecord method, specify the record name.
&REC_TASKRSRC

I
A

= &ROW_LEVEL1.GetRecord(RECORD.PSU_TASK_RSRC);

Draw a box around the cells in the table below that represent the level 1, row 2 record.
PSU_TASK_TBL

PSU_TASK_RSRC

Task

Descr

Resource
Name

0001

Tools I
Guide

e
l
c

e
t
In

a
r
O

PeopleSoft Proprietary and Confidential

DERIVED_TRAIN

PSU_TASK_EFFORT

Pct
Avail

Resource Status

Effort Date

Effort
Amount

50

Semi-Dedicated
11/16/01

7.0

11/15/01

8.0

11/14/01

6.0

11/13/01

6.0

01/08/02

9.5

01/07/02

10.0

l&

a
n
r
Ed Kelly

Jim Gutenkauf

100

Dedicated

65

Referencing Data in the Component Buffer

Lesson 13

01/05/02

12.0

Step 7. Getting a level 1 field.


A record contains one or more fields.
Using the level 1 record object with the GetField method, specify the field name.
&FLD_PCTAVAIL

= &REC_TASKRSRC.GetField(FIELD.PCT_AVAILABLE);

The code above returns a reference to single field. Draw a box around the cells that
represents that field .
PSU_TASK_TBL

PSU_TASK_RSRC

DERIVED_TRAIN

PSU_TASK_EFFORT

Task

Descr

Resource
Name

Pct
Avail

Resource Status

Effort Date

Effort
Amount

0001

Tools I
Guide
Ed Kelly

50

Semi-Dedicated
11/16/01

7.0

11/15/01

8.0

11/14/01

6.0

y
l
n

11/13/01
Jim Gutenkauf

100

Dedicated

O
e

01/08/02

I
A

s
U

6.0

9.5

01/07/02

10.0

01/05/02

12.0

This concludes the activity. Do not continue.

&
l
a

n
r
te

n
I
e

l
c
a

r
O
66

PeopleSoft Proprietary and Confidential

Lesson 13

Referencing Data in the Component Buffer

Activity 19:

Traversing the Data Buffer


In this activity, you will review the activity overview and traverse a Student Enrollment
rowset to check for the prerequisite to a course.
See PeopleCode: Activity Guide, Referencing Data in the Component Buffer, Activity
19: Traversing the Data Buffer.

Slide 226 ______________________________________________________________________________________________________

Activity Overview
On the Student Enrollment component (PSU_STU_ENROLL), do not allow enrollment
into a PeopleCode class (course 1011) unless the student has enrolled in a PeopleTools II
(course 1002) class at an earlier date. Begin by simply checking for the prerequisite,
regardless of date. Once that works, add the logic to check for an earlier start date.
Course enrollment can occur on multiple pages. This activity uses Student Enrollment.
Make sure to take this into consideration.
Select Courses, Student Enrollment to access the Student Enrollment page.

Traversing the Data Buffer

y
l
n

Here is an example of PeopleCode that would work to traverse the data buffer to check
for prerequisites. You may find a different solution.

O
e

[PSU_STU_ENROLL.GBL.PSU_STU_ENROLL-SaveEdit]
If PSU_STU_ENROLL.COURSE = "1011" And

s
U

PSU_STU_ENROLL.ENROLL_STATUS = "ENR" Then


Local boolean &Completed = False;

I
A

Local Rowset &RS;


Local Record &RecStuEnroll;

Local Field &Course, &Status;

&
l
a

Local date &StartDate, &PreReqStart;


&RS = GetRowset();

n
r
te

&StartDate = GetField(PSU_CRS_SESSN.START_DATE).Value;
For &I = 1 To &RS.ActiveRowCount

n
I
e

&RecStuEnroll = &RS.GetRow(&I).GetRecord(Record.PSU_STU_ENROLL);
&Course = &RecStuEnroll.COURSE;

cl

a
r
O

&Status = &RecStuEnroll.ENROLL_STATUS;

&PreReqStart =
&RS.GetRow(&I).GetRecord(Record.PSU_CRS_SESSN).START_DATE.Value;
If &Course.Value = "1002" And
(&Status.Value = "ENR" Or
&Status.Value = "CMP") Then
If &PreReqStart < &StartDate Then
&Completed = True;
Break;

PeopleSoft Proprietary and Confidential

67

Referencing Data in the Component Buffer

Lesson 13

End-If;
End-If;
End-For;
If Not &Completed Then
Error MsgGet(30420, 3, "MESSAGE NOT FOUND: Gotta have the prereq");
End-If;
End-If;

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
68

PeopleSoft Proprietary and Confidential

Lesson 13

Referencing Data in the Component Buffer

Activity 20:

Accessing Multiple Occurs Levels


In this activity, you will review the activity overview, then modify the Task Resources
and Efforts component to add up the effort amounts attributed to each resource and
display the total for that resource on the page. Then you will make all the Task Effort
occurs level rows display-only when a task has been completed.
See PeopleCode: Activity Guide, Referencing Data in the Component Buffer, Activity
20: Accessing Multiple Occurs Levels.

Slide 229 ______________________________________________________________________________________________________

Activity Overview
For this activity, make the following enhancements to the Task Resources component.
1. On the Task Resources page, add up the effort amounts attributed to each resource
and display the total for that resource on the page.
If the effort for a date changes, recalculate the total by finding the prior value of
effort, subtracting that from the total, then adding the new effort to the total.
2. Once a resource has finished a task, make all the Task Effort occurs level rows
display-only (occurs level two).

y
l
n

Accessing Multiple Occurs Levels

O
e

1. On the Task Resources page, add up the effort amounts attributed to each resource
and display the total for that resource on the page.
a. Create a new field, TOTAL_RES_HRS.

I
A

s
U

b. Add the field to the record definition DERIVED_TRAIN.

c. Add the field to the PSU_TASK_RESOURCES page at level 1.

&
l
a

d. Make the field display-only.

e. Add the following PeopleCode.

n
r
te

[PSU_TASK_EFFORT.EFFORT_AMT-RowInit]
/* UniqueID------------------------------------*/

n
I
e

DERIVED_TRAIN.TOTAL_RES_HRS =DERIVED_TRAIN.TOTAL_RES_HRS +
PSU_TASK_EFFORT.EFFORT_AMT;

l
c
a

r
O

[PSU_TASK_EFFORT.EFFORT_AMT-RowDelete]
/* UniqueID------------------------------------*/
DERIVED_TRAIN.TOTAL_RES_HRS =DERIVED_TRAIN.TOTAL_RES_HRS
PSU_TASK_EFFORT.EFFORT_AMT;
[PSU_TASK_EFFORT.EFFORT_AMT-FieldChange]
/* UniqueID------------------------------------*/

PeopleSoft Proprietary and Confidential

69

Referencing Data in the Component Buffer

Lesson 13

DERIVED_TRAIN.TOTAL_RES_HRS =DERIVED_TRAIN.TOTAL_RES_HRS + EFFORT_AMT PriorValue(PSU_TASK_EFFORT.EFFORT_AMT);

2. Once a resource has finished a task, make all the Task Effort occurs level rows
display-only (occurs level two).
Add the following PeopleCode.
[PSU_TASK_EFFORT.EFFORT_DT-RowInit]
/* UniqueID------------------------------------*/
If PSU_TASK_RSRC.COMPLETED_FLAG = "Y" Then
Local Record &Rec_TaskEffort;
&Rec_TaskEffort = GetRecord();

/* Current Context */

&Rec_TaskEffort.EFFORT_DT.Enabled = False;
&Rec_TaskEffort.EFFORT_AMT.Enabled = False;
&Rec_TaskEffort.CHARGE_BACK.Enabled = False;
End-If;
[PSU_TASK_RSRC.COMPLETED_FLAG-FieldChange]
/* UniqueID------------------------------------*/
Local Rowset &RS_Level2;
Local Row

&Row_Level1;

Local Record &Rec_TaskEffort;


/*

y
l
n

Current Context - GetRow() assumes current row */

&Row_Level1 = GetRow();

O
e

&RS_Level2 = &Row_Level1.GetRowset(Scroll.PSU_TASK_EFFORT);
If PSU_TASK_RSRC.COMPLETED_FLAG = "Y" Then

I
A

For &I = 1 To &RS_Level2.ActiveRowCount

s
U

&Rec_TaskEffort = &RS_Level2(&I).PSU_TASK_EFFORT;

&Rec_TaskEffort.EFFORT_DT.Enabled = False;

&
l
a

&Rec_TaskEffort.EFFORT_AMT.Enabled = False;
&Rec_TaskEffort.CHARGE_BACK.Enabled = False;
End-For;

n
r
te

Else

For &I = 1 To &RS_Level2.ActiveRowCount


&Rec_TaskEffort = &RS_Level2(&I).PSU_TASK_EFFORT;

In

&Rec_TaskEffort.EFFORT_DT.Enabled = True;

e
l
c

a
r
O
70

&Rec_TaskEffort.EFFORT_AMT.Enabled = True;
&Rec_TaskEffort.CHARGE_BACK.Enabled = True;

End-For;

End-If;

This concludes the activity. Do not continue.

PeopleSoft Proprietary and Confidential

Lesson 14

Creating Custom Objects with


Application Classes

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

71

Creating Custom Objects with Application Classes

Activity 21:

Lesson 14

Writing an Application Class


In this activity, you will review the activity overview and create an application class with
a very simple PeopleCode program.
See PeopleCode: Activity Guide, Creating Custom Objects with Application Classes,
Activity 21: Writing an Application Class.

Slide 239 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will create a new application containing a very simple PeopleCode,
the classic Hello World.

Writing an Application Class


To write an application class you will:
1. Create a new application package.
2. Insert an application class.
3. Add PeopleCode to the application class.

y
l
n

Creating a New Application Package

O
e

To create a new application package:


1. In Application Designer, select File, New.
2. Choose Application Package.
3. Name the application package PSU.
Inserting an Application Class

&
l
a

I
A

s
U

To insert an application class:

n
r
te

1. Right-click the application package you just created.


2. Select Insert App Class.

n
I
e

3. For Class Name, enter HelloWorld.

l
c
a

Adding PeopleCode to the Application Class

r
O

To add PeopleCode to an Application Class:


1. Enter the following PeopleCode in your application class.
class HelloWorld
method Greeting();
end-class;

72

PeopleSoft Proprietary and Confidential

Lesson 14

Creating Custom Objects with Application Classes

method Greeting
WinMessage("Hello World", 0);
end-method;

2. Save.
You will test your application class in a later activity.
This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

73

Creating Custom Objects with Application Classes

Activity 22:

Lesson 14

Calling Hello World


In this activity, you will review the activity overview and write a PeopleCode program
that calls the HelloWorld class you created earlier.
See PeopleCode: Activity Guide, Creating Custom Objects with Application Classes,
Activity 22: Calling Hello World.

Slide 249 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will write a simple PeopleCode that calls the HelloWorld class you
created in the last activity.

Calling Hello World


For convenience, you will add your code to FieldEdit on the Get Enrollments Refresh
button.
1. In Application Designer, open the component definition PSU_GET_ENROLL.
2. Access the FieldEdit event for DERIVED_ED_SVCS.REFRESH_BTN.

y
l
n

You are using FieldEdit because there is already code in FieldChange.


3. Add the following PeopleCode.

O
e

[PSU_GET_ENROLL.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldEdit]
/* Import the class */
import PSU:HelloWorld;

I
A

/* Declare an object using the class */


Local HelloWorld &Hi;

&
l
a

s
U

/* Instantiate an object using the class */


&Hi = create HelloWorld();

n
r
te

/* Use the object */


&Hi.Greeting();

n
I
e

4. Test. In the browser, select Set Up Training, Training Tasks, Get Enrollments.
Select the Refresh button.

l
c
a

r
O

You should see a message saying Hello World.

5. Remove or comment out the PeopleCode in PSU_GET_ENROLL.


You will use this component again in a future activity.
This concludes the activity. Do not continue.

74

PeopleSoft Proprietary and Confidential

Lesson 14

Creating Custom Objects with Application Classes

Activity 23:

Using Application Classes


In this activity, you will review the activity overview and create and use a class called
Order_Number to create a new purchase number.
See PeopleCode: Activity Guide, Creating Custom Objects with Application Classes,
Activity 23: Using Application Classes.

Slide 250 ______________________________________________________________________________________________________

Activity Overview
Earlier you saw an example of a function that could be called to create a new purchase
order number. Borrowing code from that function, you will create an application class to
accomplish the same task, and modify the PeopleCode that calls the function to call the
application class instead.
Insert a new application class called Order_Number in the application package PSU
Open the PeopleCode program .
Use the function assign_order_number() on
FUNCLIB_ED_SVCS.Order_NBR.FieldFormula as the basis for your new application
class.

y
l
n

Remember to:

O
e

Declare the class.

Declare properties and methods.

Declare private constants, instance variables, and methods.

Define methods.

Define get and set properties if appropriate.

I
A

&
l
a

s
U

Modify the PeopleCode in PSU_PO_HR.ORDER_NBR.SavePreChange to call the


application class instead of the function.

n
r
te

Remember to:

Import the class.

Declare an object.

Instantiate the object.

Call the method.

n
I
e

l
c
a

r
O

Do the following to test.

Select Purchasing, Maintain Purchase Orders, Add a New Value.

PeopleSoft Proprietary and Confidential

75

Creating Custom Objects with Application Classes

Lesson 14

Accept the defaults and select Add.

Save.

Was a new order number assigned correctly?

Using Application Classes


To create and use a new application class, perform the following steps:
1. Open the application package PSU.
2. Insert a new application class called Order_Number.
3. Open the PeopleCode program FUNCLIB_ED_SVCS.Order_NBRFieldFormula.
4. Use the function assign_order_number() program as the basis for your new
application class.
[PSU.Order_Number.OnExecute]
/* ! Assign Order Number. Assumes 8 character id. */
class Order_Number;
rem method Order_Number(&ORDER_NBR As Field out);
method Assign_Order_Number(&ORDER_NBR As string) Returns string;

y
l
n

private
Constant &LENGTH = 8;

O
e

instance string &CHECK;


instance string &PAD;
instance number &NBR;
end-class;

I
A

method Assign_Order_Number
/+ &ORDER_NBR as String +/
/+ Returns String +/

&
l
a

Local string &Last_Order;

s
U

&CHECK = Rept("9", &LENGTH);

n
r
te

SQLExec("Select order_last

From PS_INSTALLATION_TR", &Last_Order);

If Value(&Last_Order) + 1 > Value(&CHECK) Then


Error MsgGet(10001, 4, "MESSAGE NOT FOUND.", &CHECK);

n
I
e
Else

&NBR = Value(&Last_Order) + 1;

l
c
a

r
O

&PAD = Rept(0, 8 Len(RTrim(LTrim(&Last_Nbr, 0))));


&ORDER_NBR = &PAD | String(&NBR);

SQLExec("Update PS_INSTALLATION_TR Set order_last = :1",


&ORDER_NBR);
Return &ORDER_NBR;
End-If;
end-method;

76

PeopleSoft Proprietary and Confidential

Lesson 14

Creating Custom Objects with Application Classes

5. Modify the PeopleCode in PSU_PO_HR.ORDER_NBR.SavePreChange to call the


application class instead of the function.
[PSU_PO_HR.ORDER_NBR.SavePreChange]
import PSU:Order_Number;
Local Order_Number &NewOrder;

If PSU_PO_HDR.ORDER_NBR = "NEW" And


%Mode = "A" Then
/* assign order number */
&NewOrder = create Order_Number();
PSU_PO_HDR.ORDER_NBR =
&NewOrder.Assign_Order_Number(PSU_PO_HDR.ORDER_NBR);
End-If;

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

77

Creating Custom Objects with Application Classes

Lesson 14

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
78

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 15

Using Data Buffer Methods

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

79

Using Data Buffer Methods

Activity 24:

Lesson 15

Using Select to Refresh Get Enrollments


In this activity, you will review the activity overview and add PeopleCode to the Get
Enrollments page to enable it to select students enrolled in a specified course session.
See PeopleCode: Activity Guide, Using Data Buffer Methods, Activity 24: Using
Select to Refresh Get Enrollments.

Slide 256 ______________________________________________________________________________________________________

Activity Overview
The purpose of the Get Enrollments page is to allow a user to get enrollment information
for course sessions without having to go through the search page for each session. The
idea is to enter a course and session number, fill in the fields, hit the Refresh push button
and retrieve all the students who are enrolled.
In this activity you will look at the elements of the Get Enrollments component and add
some PeopleCode to select the appropriate data into the scroll.

Using Select to Refresh Get Enrollments


In this activity you will:

y
l
n

1. Try out the Get Enrollments page.


2. Examine the Get Enrollments page definition.
3. Examine the Get Enrollments component definition.

O
e

s
U

4. Add PeopleCode to select rows into the Get Enrollments scroll.

I
A

5. Test.
Trying out the Get Enrollments Page

&
l
a

1. Select Set Up Training, Training Tasks, Get Enrollments.


2. For Course Code, enter 1001.

n
r
te

3. For Session Number, enter 287.

n
I
e

4. Select the Refresh push button.


5. Answer the following questions:

l
c
a

r
O

Question

Answer

What did the search page look like?


Why was the page blank when it displayed?

Why were no rows retrieved when you pushed the

80

PeopleSoft Proprietary and Confidential

Lesson 15

Using Data Buffer Methods

Question

Answer

Refresh button?

Examining the Get Enrollments Page Definition


1. In Application Designer, open the page definition PSU_GET_ENROLL.
2. Look at the page field properties for Course Code, Session Number, and the Refresh
button.
Question

Answer

With what record definition are they associated?


Why a derived/work record?

This is one case where derived/work fields are enabled and have prompt table edits.
3. Look at the Grid properties.

Double-click the grid to open the properties dialog box.

Select the Use tab.

Notice that the No Auto Select checkbox is selected.

y
l
n

O
e

The scroll or grid referenced by the rowset object should have the No Auto Select
checkbox selected to prevent the Component Processor from automatically selecting rows
into the scroll. You will take control of that with PeopleCode.

I
A

Examining the Get Enrollments Component

s
U

1. In Application Designer, open the component definition PSU_GET_ENROLL. Look


at the Component Properties, Use tab. (Leave the page definition open.).

&
l
a

2. Answer the following questions:

n
r
te

Question

What is the search record?

Answer

n
I
e

Why?

l
c
a

r
O

3. Select the page definition again.


Look at the grid properties, Use tab. Notice that No Auto Select is checked. That explains
why the page was initially blank. We dont want any rows selected into the buffer until
the user selects Refresh.

PeopleSoft Proprietary and Confidential

81

Using Data Buffer Methods

Lesson 15

Notice that the grid is set to display only. If it was enabled , the user would be able to
save changes to the database.

If the component processor doesnt load the rows, how do they get loaded?
PeopleCode!

4. Answer the following questions:


Question

Answer

Where would PeopleCode be?


Would it be on the record or the component?

Adding PeopleCode to Select Rows into the Get Enrollments Scroll


1. Select the component definition again.
2. Select the Structure tab.
3. Open the PeopleCode for REFRESH_BTN, FieldChange.
Theres no code there!
4. Add the following code:

y
l
n

Local Rowset &Rowset;


&Rowset = GetRowset(SCROLL.PSU_STU_ENROLL);

O
e

&Rowset.Select(RECORD.PSU_STU_ENROLL, "Where COURSE = :1 and SESSION_NBR


= :2", DERIVED_ED_SVCS.COURSE, DERIVED_ED_SVCS.SESSION_NBR);

I
A

Testing

s
U

1. Test using the following course sessions:

Course 1001, Session 4.

Course 1002, Session 32.

&
l
a

n
r
te

2. Select View All.

Notice that all the students from the first select are still there, along with all the
students from the second select.

n
I
e

l
c
a

r
O
82

Why?

3. Compare your Get Enrollments page with the following results:


Results
These are the enrollments for Course 1001, Session 4 and Course 1002, Session 32.

PeopleSoft Proprietary and Confidential

Lesson 15

Using Data Buffer Methods

y
l
n

O
e

Get Student Enrollments page

&
l
a

I
A

s
U

This concludes the activity. Do not continue.

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

83

Using Data Buffer Methods

Activity 25:

Lesson 15

Adding the Flush Method


In this activity, you will review the activity overview and add a Flush statement to your
PeopleCode program on the Get Enrollments component.
See PeopleCode: Activity Guide, Using Data Buffer Methods, Activity 25: Adding the
Flush Method.

Slide 258 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will add a Flush statement to your PeopleCode program on the Get
Enrollments component.

Adding the Flush Method


In this activity you will:
1. Add a Flush statement.
2. Test.
Adding a Flush Statement

y
l
n

Add the following statement to the PeopleCode program you wrote for the
PSU_GET_ENROLL component in the last activity:
&Rowset.Flush();

Your completed program should look like this.

I
A

Local Rowset &Rowset;

O
e

s
U

&Rowset = GetRowset(SCROLL.PSU_STU_ENROLL);
&Rowset.Flush();

&
l
a

&Rowset.Select(RECORD.PSU_STU_ENROLL, Where COURSE = :1 and SESSION_NBR


= :2, DERIVED_ED_SVCS.COURSE, DERIVED_ED_SVCS.SESSION_NBR);

Testing

n
r
te

1. Test using the following course sessions:

n
I
e

l
c
a

r
O
84

Course 1001, Session 4.

Course 1002, Session 32.

2. Select View All.


Notice that only the students from the second select are displayed.

3. Compare your Get Enrollments page with the following results:

PeopleSoft Proprietary and Confidential

Lesson 15

Using Data Buffer Methods

Results:
These are the enrollments for Course 1002, Session 32.

y
l
n

Get Student Enrollments page


This concludes the activity. Do not continue.

I
A

&
l
a

O
e

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

85

Using Data Buffer Methods

Lesson 15

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
86

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 16

Executing SQL in PeopleCode

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

87

Executing SQL in PeopleCode

Activity 26:

Lesson 16

Updating Effort Spent With a SQLExec Statement


In this activity, you will review the activity overview and write a SQLExec statement
that automatically updates the Effort Spent field whenever the Refresh button is pushed.
See PeopleCode: Activity Guide, Executing SQL in PeopleCode, Activity 26: Updating
Effort Spent With a SQLExec Statement.

Slide 273 ______________________________________________________________________________________________________

Activity Overview
It just doesnt make sense that users have to manually update the Effort Spent field.
Thats a perfect job for PeopleCode.
In this activity you will add a push button to the page and write a SQLExec statement
that automatically calculates the Effort Spent field whenever the Refresh button is
clicked.

Updating Effort Spent With a SQLExec Statement


To update Effort Spent with a SQLExec statement:
1. Open the PSU_TASK page in Application Designer.

y
l
n

a. Make the Effort Spent field display only.

O
e

b. Add a Refresh push button associated with the record field


DERIVED_ED_SVCS.REFRESH_BTN.
2. Add the following PeopleCode:

I
A

s
U

[PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange]

/* Update Effort_Spent whenever the user chooses to refresh it using the


pushbutton to reflect actual values in Effort_Amt */

&
l
a

SQLExec("Select Sum(EFFORT_AMT) from PS_PSU_TASK_EFFORT where TASK = :1",


PSU_TASK_TBL.TASK, PSU_TASK_TBL.EFFORT_SPENT);

n
r
te

3. Test.

a. Navigate to the Task page.

n
I
e

l
c
a

r
O
88

b. Note the value of the Effort Spent field when you first open the component.
c. Click the Refresh pushbutton and observe the change.

The Effort Spent field should now reflect the sum of all effort amounts recorded for
this task on the Task Resources page.

This concludes the activity. Do not continue.

PeopleSoft Proprietary and Confidential

Lesson 16

Executing SQL in PeopleCode

Activity 27:

Creating a SQL Definition


In this activity, you will review the activity overview and create a SQL definition, then
replace the SQL string in a SQLExec statement with the SQL definition you created.
See PeopleCode: Activity Guide, Executing SQL in PeopleCode, Activity 27: Creating
a SQL Definition.

Slide 275 ______________________________________________________________________________________________________

Activity Overview
Many of the early limitations of SQLExec are resolved by using SQL definitions in your
SQLExec functions. No more black box string literals that cannot be maintained by
PeopleTools, plus SQL definitions add platform independence and code reusability.
In this activity, you will create a new SQL definition in Application Designer. Then you
will substitute that SQL definition for the quoted SQL statement in the SQLExec you
created earlier to select the sum of Effort Amount entries for a given task.

Creating a SQL Definition


In this activity you will:

y
l
n

1. Create a SQL definition to sum Effort Amounts for all resources assigned to a task.
2. Explore the features of the SQL Editor.

O
e

3. Replace the SQL string in a SQLExec statement with the SQL definition you
created.

I
A

Creating a new SQL Definition


To create a new SQL definition:

s
U

1. In Application Designer, select File, New.

&
l
a

2. For the definition type, choose SQL.

n
r
te

3. Select OK.

4. Add the SQL statement below. If you copy and paste from
PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange
PeopleCode, be sure to add the %Table Meta-SQL.

n
I
e

cl

ra

Select Sum(EFFORT_AMT) from %Table(PSU_TASK_EFFORT) where TASK = :1

5. Save your definition as PSU_EFFORT_SUM.

Exploring the SQL Editor


While youre here, take a minute to look at some other features of the SQL Editor.
1. Select the dropdown under the title bar.

PeopleSoft Proprietary and Confidential

89

Executing SQL in PeopleCode

Lesson 16

You can write database-specific SQL and associate it with the appropriate platform in
the SQL definition. Along with meta-SQL, this gives you another level of databaseindependence.
2. Right-click in the editor pane and choose Resolve Meta-SQL from the popup menu.
Notice the output window shows what the SQL looks like when it executes. In this
case, it resolves the record name in %Table by adding PS_ as a prefix to it.
This handy bit of meta-SQL allows the use of record names instead of table names in
the SQL definition, which is a huge plus at upgrade time. The black box problem
we encountered with quoted literals is eliminated.
3. Select the Properties button (or ALT+ENTER, or right-click and choose Definition
Properties), choose the Advanced tab, and select the Show Effective Date checkbox.
OK.
SQL Definitions are effective-dated. By showing the effective date in the Editor
window, you can effective-date versions of your code.
Using a SQL Definition in PeopleCode
Many of the early limitations of SQLExec are resolved by using SQL definitions in your
SQLExec functions. No more black box string literals that cannot be maintained by
PeopleTools, plus platform independence and code reusability.
To rewrite a SQLExec statement to use the SQL definition you created:

y
l
n

1. Open the program you created in the previous activity, in


PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange.

O
e

It should look like this:

s
U

SQLExec("Select Sum(EFFORT_AMT)from PS_PSU_TASK_EFFORT where TASK = :1",


PSU_TASK_TBL.TASK, PSU_TASK_TBL.EFFORT_SPENT);

I
A

2. Modify the PeopleCode to use the SQL definition instead of the SQL statement in a
quoted literal.

SQLExec(SQL.PSU_EFFORT_SUM, PSU_TASK_TBL.TASK,
PSU_TASK_TBL.EFFORT_SPENT);

&
l
a

3. Test using the new PeopleCode.

n
r
te

4. Select Set Up Training, Training Tasks, Task Table.

n
I
e

Verify that the Effort Spent field is updating properly.

This concludes the activity. Do not continue.

l
c
a

r
O
90

PeopleSoft Proprietary and Confidential

Lesson 16

Executing SQL in PeopleCode

Activity 28:

Using a SQL Object


In this activity, you will review the activity overview and modify the PeopleCode you
created in PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange to use
a SQL object.
See PeopleCode: Activity Guide, Executing SQL in PeopleCode, Activity 28: Using a
SQL Definition with a SQL Object.

Slide 280 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will modify the
PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange PeopleCode
program to use a SQL object instead of a SQLExec statement.

Using a SQL Object


To modify your PeopleCode to use a SQL object:
1. In Application Designer, open
PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange and edit the
code so it looks like this:

y
l
n

/* Whenever the refresh button is invoked, update EFFORT_SPENT to reflect


actual values in EFFORT_AMT */

O
e

/* Declare the SQL object */


Local SQL &SelectEffort;

I
A

Local Number &Spent;

s
U

/* Instantiate the SQL object using the SQL Definition */

&SelectEffort = GetSQL(SQL.PSU_EFFORT_SUM, PSU_TASK_TBL.TASK);

&
l
a

If &SelectEffort.Fetch(&Spent) Then

n
r
te

PSU_TASK_TBL.EFFORT_SPENT.value = &Spent;

n
I
e

DERIVED_TRAIN.EFFORT_TO_GO.Value = PSU_TASK_TBL.EFFORT_TOTAL.value PSU_TASK_TBL.EFFORT_SPENT.value;

cl

a
r
O

End-If;

2. Test.
This concludes the activity. Do not continue.

PeopleSoft Proprietary and Confidential

91

Executing SQL in PeopleCode

Activity 29:

Lesson 16

Choosing the Best SQL Option


In this activity, you will review the activity overview and list the pros and cons of the
different ways to execute SQL in PeopleSoft.
See PeopleCode: Activity Guide, Executing SQL in PeopleCode, Activity 29: Choosing
the Best SQL Option.

Slide 287 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will discuss as a class the advantages and disadvantages of using the
various options you have learned for executing SQL in PeopleSoft. Bear in mind that the
Component Processor is also using SQL to select and update data in the database.

Choosing the Best SQL Option


If there was one best way to do everything, you wouldnt need choices. PeopleSoft gives
you several choices for executing SQL because each option has its pros and cons in
different situations.
Fill in the tables below with the pros and cons of each option.

y
l
n

Component Processor
Pros

Cons

I
A

SQL Definition
Pros

e
l
c

e
t
In

rn

&
l
a

O
e

s
U

Cons

a
r
O
92

PeopleSoft Proprietary and Confidential

Lesson 16

Executing SQL in PeopleCode

SQLExec
Pros

Cons

SQL Object
Pros

Cons

y
l
n

Record Object
Pros

O
e

Cons

I
A

&
l
a

s
U

This concludes the activity. Do not continue.

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

93

Executing SQL in PeopleCode

Activity 30:

Lesson 16

Executing SQL in PeopleCode


In this activity, you will review the activity overview and upgrade a SQLExec to use
object-oriented PeopleCode. Then you will use a Record object to keep Effort Spent
current.
See PeopleCode: Activity Guide, Executing SQL in PeopleCode, Activity 30:
Executing SQL in PeopleCode.

Slide 289 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will use two of the techniques you have learned to execute SQL
statements from within PeopleCode.
Use the appropriate SQL technique to accomplish the following tasks:
1. Upgrading a SQLExec to Object-Oriented PeopleCode.
Earlier in this lesson you saw an example of a SQLExec that was used in
SavePostChange to update the Student Table, PSU_STUDENT_TBL, when an
address was changed on the Customer Table, PSU_CUST_TBL.

y
l
n

For this activity, you will:

Create a new SQL definition, add the SQL statement to it, and Save As
PSU_UPDATE_STUDENT.

Modify the code in the PSU_CUST component to use a SQL object and your
new SQL definition.

Test. Change an address on the Customer Table. The change should appear on
the Student Table for a student who works for that customer and has Same
Address as Customer checked.

O
e

I
A

&
l
a

s
U

2. Using a Record Object to Keep Effort Spent Current.


In this lesson you wrote some SQL that updated Effort Spent on the Task Table.

n
r
te

The problem with that is that Effort Spent is never updated until a user opens that
page, which can lead to a data integrity problem.

n
I
e

l
c
a

r
O

For instance, if someone were to use Effort Spent in a report, it would not necessarily
be accurate.
Modify your application so that Effort Spent will always be current.
Use a record object in your solution.

Executing SQL in PeopleCode


Following are potential solutions to the activity.

94

PeopleSoft Proprietary and Confidential

Lesson 16

Executing SQL in PeopleCode

Upgrading a SQLExec to Object-Oriented PeopleCode


Earlier in this lesson you saw an example of a SQLExec that was used in
SavePostChange to update the Student Table, PSU_STUDENT_TBL, when an address
was changed on the Customer Table, PSU_CUST_TBL.
1. Create a new SQL definition, add the SQL statement to it, and Save As
PSU_UPDATE_STUDENT.
[PSU_UPDATE_STUDENT.0 (SQL Definition)]
UPDATE %Table(PSU_STUDENT_TBL)
SET STREET1 = :1, CITY = :2, STATE = :3, ZIP = :4, COUNTRY = :5, PHONE =
:6
WHERE CUSTOMER_ID = :7
AND SAME_ADDR_CUSTOMER = 'Y'

2. Modify the code in the PSU_CUST component to use a SQL object and your new
SQL definition.
[PSU_CUST.GBL-SavePostChange]
If FieldChanged(PSU_CUST_TBL.STREET1) Or
FieldChanged(PSU_CUST_TBL.CITY) Or
FieldChanged(PSU_CUST_TBL.STATE) Or
FieldChanged(PSU_CUST_TBL.ZIP) Or
FieldChanged(PSU_CUST_TBL.COUNTRY) Or

y
l
n

FieldChanged(PSU_CUST_TBL.PHONE) Then

SQLExec(SQL.PSU_UPDATE_STUDENT, PSU_CUST_TBL.STREET1, PSU_CUST_TBL.CITY,


PSU_CUST_TBL.STATE, PSU_CUST_TBL.ZIP, PSU_CUST_TBL.COUNTRY,
PSU_CUST_TBL.PHONE, PSU_CUST_TBL.CUSTOMER_ID);

O
e

End-if;

Using a Record Object to Keep Effort Spent Current.

I
A

s
U

In this lesson you wrote some SQL that updated Effort Spent on the Task Table.
The problem with that is that Effort Spent is never updated until a user opens the Task
Table page, even though it may have been changed on the Task Resources page. This can
lead to a data integrity problem.

&
l
a

For instance, if someone were to use Effort Spent in a report, it would not necessarily be
accurate.

n
r
te

Modify your application so that Effort Spent will always be current.

n
I
e

Use a record object in your solution.

l
c
a

r
O

[PSU_TASK_EFFORT.EFFORT_AMT-SavePostChange]

Local Field &Amt;


Local Record &TaskRec;
&Amt = GetField();
If &Amt.IsChanged Then
SQLExec("Select Sum(EFFORT_AMT) from PS_PSU_TASK_EFFORT where TASK =
:1", PSU_TASK_EFFORT.TASK, &EffortSum);

PeopleSoft Proprietary and Confidential

95

Executing SQL in PeopleCode

Lesson 16

&TaskRec = CreateRecord(Record.PSU_TASK_TBL);
&TaskRec.TASK.Value = PSU_TASK_EFFORT.TASK;
&TaskRec.EFFORT_SPENT.Value = &EffortSum;
&TaskRec.Update();
End-If;

This concludes the activity. Do not continue.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O
96

PeopleSoft Proprietary and Confidential

Lesson 17

Final Course Activity

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

97

Final Course Activity

Activity 31:

Lesson 17

Using a Standalone Rowset to Track Overtime Hours


In this activity, you will review the activity overview and write a PeopleCode program
that tracks overtime hours using a standalone rowset.
See PeopleCode: Activity Guide, Final Course Activiy, Activity 31: Using a
Standalone Rowset to Track Overtime Hours.

Slide 293 ______________________________________________________________________________________________________

Activity Overview
In this activity, you will have the opportunity to bring together some of the concepts you
have learned.
A requirement has been identified to place a field on the Task page that will track
overtime hours for each task.
To accomplish this, you will need to create a standalone rowset that contains all the
efforts for a task. Then loop through that rowset and check each row for effort amount. If
the effort is greater than 8, add the amount over 8 to an accumulator.
(You may think of another way to accomplish this. Try it first using a standalone rowset,
then when this is working, try it your way.)

y
l
n

Display the accumulator on the Task page. Include a button on the Task page to refresh
the Total Overtime field.

O
e

After you get your SQL working with a quoted literal, store the SQL statement in a SQL
definition and modify your program to use the SQL definition.

I
A

Using a standalone rowset to track overtime hours

s
U

To place a field on the Task page that will track total overtime hours for a each task,
perform the following tasks:

&
l
a

1. Display the accumulator on the Task page.


2. Create a standalone rowset.

n
r
te

3. Populate the rowset using a data buffer method.

n
I
e

4. Loop through the rows in the rowset to check overtime hours.

l
c
a

Displaying the accumulator on the Task page.

r
O

To display the accumulator on the Task page:


1. Create a new number field, TOTAL_OT.
2. Add TOTAL_OT to the DERIVED_TRAIN record definition.
3. Place a display-only field on the page and associate the field with
DERIVED_TRAIN.TOTAL_OT.

98

PeopleSoft Proprietary and Confidential

Lesson 17

Final Course Activity

4. Put a button on the Task page to refresh the Total Overtime field.
5. Associate it with the field DERIVED_ED_SVCS.REFRESH_BTN.
Creating a standalone rowset
To create a standalone rowset, enter the following code on the PSU_TASK_TBL
component.
[PSU_TASK.GBL.DERIVED_ED_SVCS-RowInit]

and
[PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN-FieldChange]
Local Rowset &TaskEffort;
Local number &N, &OT, &I;
&TaskEffort = CreateRowset(Record.PSU_TASK_EFFORT);

Populating the rowset using a data buffer method


Add the following code to the programs you wrote in the previous step.
&N = &TaskEffort.Fill("Where TASK = :1", PSU_TASK_TBL.TASK);

y
l
n

Looping through the rows in the rowset to check overtime hours.

O
e

Loop through your rowset and check each row for Effort Amount. If the effort is greater
than 8, add the amount over 8 to an accumulator.

s
U

Add the following code to the programs you wrote in the previous step.

I
A

DERIVED_TRAIN.TOTAL_OT.SetDefault();
For &I = 1 To &N

&OT = &TaskEffort(&I).PSU_TASK_EFFORT.EFFORT_AMT.Value - 8;
If &OT > 0 Then

&
l
a

DERIVED_TRAIN.TOTAL_OT = DERIVED_TRAIN.TOTAL_OT + &OT;


End-If;

n
r
te

End-For;

This concludes the activity. Do not continue.

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

99

Final Course Activity

Lesson 17

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
100

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Lesson 18

Course Review
This lesson has no activities.

y
l
n

O
e

I
A

&
l
a

s
U

n
r
te

n
I
e

l
c
a

r
O

PeopleSoft Proprietary and Confidential

101

Course Review

Lesson 18

Notes
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

y
l
n

______________________________________________________________________

O
e

______________________________________________________________________

s
U

______________________________________________________________________

I
A

______________________________________________________________________

______________________________________________________________________

&
l
a

______________________________________________________________________

n
r
te

______________________________________________________________________

n
I
e

______________________________________________________________________

cl

a
r
O
102

______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

PeopleSoft Proprietary and Confidential

Potrebbero piacerti anche