Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
y
l
n
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
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
Lesson 2
Technology Overview........................................................................................................3
Lesson 3
Lesson 4
y
l
n
O
e
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
I
A
&
l
a
s
U
n
r
te
n
I
e
r
O
l
c
a
Lesson 11
Lesson 12
iii
PeopleCode
Contents
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
iv
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
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
I
A
KEY+KEY
&
l
a
Monospace font
(quotation marks)
n
r
te
. . . (ellipses)
In
{ } (curly braces)
e
l
c
ra
[ ] (square brackets)
& (ampersand)
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
Related Documentation
&
l
a
s
U
n
r
te
n
I
e
See Also
cl
a
r
O
vi
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
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
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
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 3
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
Activity 1:
Lesson 3
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.
y
l
n
O
e
&
l
a
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.
Lesson 3
y
l
n
s
U
I
A
O
e
This is the most frequently forgotten step! Fortunately we dont need to build any tables.
&
l
a
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
l
c
a
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.
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:
Associate resources and efforts to the new task, including insertions and deletions
in both scrolls.
Verify that rows have been written to the appropriate database tables.
y
l
n
I
A
&
l
a
O
e
s
U
n
r
te
n
I
e
l
c
a
r
O
8
Lesson 3
Activity 2:
Slide 32 _______________________________________________________________________________________________________
y
l
n
O
e
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
n
r
te
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.
Lesson 3
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.
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
I
A
&
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 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.
Lesson 3
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
11
Activity 3:
Lesson 3
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.
y
l
n
O
e
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
n
r
te
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
r
O
12
Lesson 3
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
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
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.
13
Lesson 3
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
14
Lesson 4
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
15
Activity 4:
Lesson 4
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.
y
l
n
O
e
s
U
I
A
&
l
a
n
r
te
n
I
e
l
c
a
r
O
16
Lesson 4
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
17
Activity 5:
Lesson 4
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.
y
l
n
I
A
&C = &C + 1;
O
e
s
U
&
l
a
n
r
te
n
I
e
&C = &C + 1;
l
c
a
r
O
18
Lesson 4
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
19
Activity 6:
Lesson 4
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.
y
l
n
I
A
&C = &C + 1;
O
e
s
U
&
l
a
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
r
O
20
Lesson 4
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
21
Activity 7:
Lesson 4
Slide 60 _______________________________________________________________________________________________________
Activity Overview
In this activity, you will place a WinMessage in SaveEdit.
y
l
n
O
e
I
A
s
U
&
l
a
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
n
I
e
cl
ra
22
Lesson 4
Activity 8:
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.
O
e
s
U
I
A
y
l
n
&
l
a
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
23
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
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
24
Lesson 4
Activity 9:
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
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.
25
Lesson 4
[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
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
n
I
e
End-If;
cl
a
r
O
26
Lesson 5
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
27
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
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
29
Activity 10:
Lesson 6
Slide 95 _______________________________________________________________________________________________________
Activity Overview
In this activity, you will observe how the SetSearchDialogBehavior function is used to
bypass the search page.
y
l
n
O
e
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
&
l
a
Results
n
r
te
n
I
e
l
c
a
r
O
30
Lesson 6
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
31
Activity 11:
Lesson 6
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
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
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
Lesson 6
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.
y
l
n
O
e
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
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.
33
Lesson 6
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.
Lesson 6
y
l
n
O
e
End-If;
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
35
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 7
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
37
Activity 12:
Lesson 7
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
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.
38
Lesson 7
Make it display-only.
In the page field properties, select the Display Zero checkbox or else a blank will
be displayed.
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
[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
l
c
a
r
O
39
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
&
l
a
n
r
te
n
I
e
l
c
a
r
O
40
Lesson 7
Activity 13:
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.
y
l
n
O
e
I
A
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
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.
41
Lesson 7
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
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
n
I
e
l
c
a
r
O
42
Notice the code that populates the DERIVED.EDITTABLE field with the
appropriate value based on the value of the REVIEW_TYPE.
Lesson 8
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
43
Activity 14:
Lesson 8
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.
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.
O
e
I
A
s
U
&
l
a
d. Click Add.
n
r
te
Value or Status
Description
PeopleCode Course
e
l
c
In
Message Text
a
r
O
f.
Save.
44
Lesson 8
/* 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.
y
l
n
O
e
I
A
Page Element
s
U
Value or Status
Message Text
&
l
a
e. Save.
n
r
te
n
I
e
cl
ra
[PSU_TASK.GBL.PSU_TASK_TBL.SaveEdit]
/* UniqueID------------------------------------*/
If All(PSU_TASK_TBL.START_DT, PSU_TASK_TBL.EFFORT_TOTAL) Then
45
Lesson 8
End-If;
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
46
Lesson 9
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
47
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.
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
n
r
te
c. Save.
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
Lesson 9
[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
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;
49
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);
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
50
Lesson 10
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
51
Activity 16:
Lesson 10
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.
Answer
1.
y
l
n
2.
O
e
3.
4.
I
A
s
U
na
52
r
e
nt
Answer
1.
2.
1.
I
e
2.
l
c
a
r
O
l&
Lesson 10
Answer
Record
Field
Type
What loads?
PC?
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
53
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 11
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
55
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 12
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
57
Activity 17:
Lesson 12
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.
y
l
n
O
e
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
n
r
te
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
Lesson 12
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;
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
59
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 13
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
61
Activity 18:
Lesson 13
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.
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
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
r
O
62
&RS_Level0, &RS_Level1;
Lesson 13
Local
&Row_Level0, &Row_Level1;
Local
&Rec_TaskRsrc;
Local
&Fld_PctAvail;
= 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
&
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
63
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
= &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
64
Lesson 13
&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
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
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
Lesson 13
01/05/02
12.0
= &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
&
l
a
n
r
te
n
I
e
l
c
a
r
O
66
Lesson 13
Activity 19:
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.
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
I
A
&
l
a
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;
67
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;
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
68
Lesson 13
Activity 20:
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
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
&
l
a
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------------------------------------*/
69
Lesson 13
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;
y
l
n
&Row_Level1 = GetRow();
O
e
&RS_Level2 = &Row_Level1.GetRowset(Scroll.PSU_TASK_EFFORT);
If PSU_TASK_RSRC.COMPLETED_FLAG = "Y" Then
I
A
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
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;
Lesson 14
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
71
Activity 21:
Lesson 14
Activity Overview
In this activity, you will create a new application containing a very simple PeopleCode,
the classic Hello World.
y
l
n
O
e
&
l
a
I
A
s
U
n
r
te
n
I
e
l
c
a
r
O
72
Lesson 14
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
73
Activity 22:
Lesson 14
Activity Overview
In this activity, you will write a simple PeopleCode that calls the HelloWorld class you
created in the last activity.
y
l
n
O
e
[PSU_GET_ENROLL.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldEdit]
/* Import the class */
import PSU:HelloWorld;
I
A
&
l
a
s
U
n
r
te
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
74
Lesson 14
Activity 23:
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
Define methods.
I
A
&
l
a
s
U
n
r
te
Remember to:
Declare an object.
n
I
e
l
c
a
r
O
75
Lesson 14
Save.
y
l
n
private
Constant &LENGTH = 8;
O
e
I
A
method Assign_Order_Number
/+ &ORDER_NBR as String +/
/+ Returns String +/
&
l
a
s
U
n
r
te
SQLExec("Select order_last
n
I
e
Else
&NBR = Value(&Last_Order) + 1;
l
c
a
r
O
76
Lesson 14
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
77
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 15
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
79
Activity 24:
Lesson 15
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.
y
l
n
O
e
s
U
I
A
5. Test.
Trying out the Get Enrollments Page
&
l
a
n
r
te
n
I
e
l
c
a
r
O
Question
Answer
80
Lesson 15
Question
Answer
Refresh button?
Answer
This is one case where derived/work fields are enabled and have prompt table edits.
3. Look at the Grid properties.
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
s
U
&
l
a
n
r
te
Question
Answer
n
I
e
Why?
l
c
a
r
O
81
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!
Answer
y
l
n
O
e
I
A
Testing
s
U
&
l
a
n
r
te
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?
Lesson 15
y
l
n
O
e
&
l
a
I
A
s
U
n
r
te
n
I
e
l
c
a
r
O
83
Activity 25:
Lesson 15
Activity Overview
In this activity, you will add a Flush statement to your PeopleCode program on the Get
Enrollments component.
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();
I
A
O
e
s
U
&Rowset = GetRowset(SCROLL.PSU_STU_ENROLL);
&Rowset.Flush();
&
l
a
Testing
n
r
te
n
I
e
l
c
a
r
O
84
Lesson 15
Results:
These are the enrollments for Course 1002, Session 32.
y
l
n
I
A
&
l
a
O
e
s
U
n
r
te
n
I
e
l
c
a
r
O
85
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
Lesson 16
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
87
Activity 26:
Lesson 16
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.
y
l
n
O
e
I
A
s
U
[PSU_TASK.GBL.DERIVED_ED_SVCS.REFRESH_BTN.FieldChange]
&
l
a
n
r
te
3. Test.
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.
Lesson 16
Activity 27:
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.
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
s
U
&
l
a
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
89
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
O
e
s
U
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
n
r
te
n
I
e
l
c
a
r
O
90
Lesson 16
Activity 28:
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.
y
l
n
O
e
I
A
s
U
&
l
a
If &SelectEffort.Fetch(&Spent) Then
n
r
te
PSU_TASK_TBL.EFFORT_SPENT.value = &Spent;
n
I
e
cl
a
r
O
End-If;
2. Test.
This concludes the activity. Do not continue.
91
Activity 29:
Lesson 16
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.
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
Lesson 16
SQLExec
Pros
Cons
SQL Object
Pros
Cons
y
l
n
Record Object
Pros
O
e
Cons
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
93
Activity 30:
Lesson 16
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
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
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.
94
Lesson 16
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
O
e
End-if;
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
n
I
e
l
c
a
r
O
[PSU_TASK_EFFORT.EFFORT_AMT-SavePostChange]
95
Lesson 16
&TaskRec = CreateRecord(Record.PSU_TASK_TBL);
&TaskRec.TASK.Value = PSU_TASK_EFFORT.TASK;
&TaskRec.EFFORT_SPENT.Value = &EffortSum;
&TaskRec.Update();
End-If;
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
96
Lesson 17
y
l
n
O
e
I
A
&
l
a
s
U
n
r
te
n
I
e
l
c
a
r
O
97
Activity 31:
Lesson 17
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
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
n
r
te
n
I
e
l
c
a
r
O
98
Lesson 17
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);
y
l
n
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
n
r
te
End-For;
n
I
e
l
c
a
r
O
99
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
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
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
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________