Você está na página 1de 43

PeopleCode

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

PeopleCode

People Tools - 3 Day Class

PeopleCode
Table of Contents

1.1: Review 3 days Agenda ................................................................................ 3 Day 2:........................................................................................................................... 4 2.1: Review the Day 2 agenda ........................................................................ 4 2.2: Explaining component buffer .................................................................. 4 2.3: Understanding execution flow in multi level pages........................ 5 2.4: Understanding PeopleCode Language ................................................. 6 2.5: Discussing Events in Detail.................................................................... 15 2.6: Understanding Add Mode Processing................................................. 41 2.7: Understanding Deferred Processing ................................................... 42

PeopleCode
1.1: Review 3 days Agenda

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

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

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

PeopleCode

Day 2: 2.1: Review the Day 2 agenda

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

2.2:

Component buffer is the area in memory that stores data for the currently active component. The component buffer consists of rows of buffer fields that hold data for the records associated with page controls, including primary scroll records, related display records, derived/work records, and Translate table records. PeopleCode can reference buffer fields associated with page controls and other buffer fields from the primary scroll record and related display records. How does a component buffer get populated? The component processor allocates temporary buffers on the application server to hold the application data for a component. The search page gives you the list of the primary keys for a component. When a value is selected from the search page, all related data necessary to populate the component pages are retrieved from the database. Data is retrieved for all the records that are associated with the component (i.e. the records that appear on the component structure tab of the component definition on the application designer). Whenever changes are made to the data on the component pages the data of the component buffer is also modified but does not affect the database. However, on pressing the save button the data in the component buffer gets committed to the database.

PeopleCode
Records accessed while opening the below component:

2.3:

Understanding execution flow in multi level pages

Component buffer is structured and the contents of the data buffer are loaded based on the rules of allocation. The buffer allocation process is a depth-first algorithm. The buffer starts at level 0 and drills down to lower levels row by row in a parent to child, child to grandchild, grandchild to great grandchild manner. In components where there are a level 0, a level 1 and a level 2, level 0 is first loaded. Then the component processor drills down to level 1 and loads the first row it finds, and then drills down to see if that row has any children. If it does, it drills down to load the first row it finds, and then looks to see if it has any children, and so on. This is the depth-first algorithm.

PeopleCode
Hierarchical scroll path taken to access any buffer for 2 levels:

Activity 5 Design a page with 2 level of buffer and examine loading In this activity, students will design a page to access book lending application we developed in Application Designer class. That application comprised of three pages <STU_INITIALS>_TITLE_TBL, <STU_INITIALS>_VOLUME_TBL and <STU_INITIALS>_BORROW_DTL. These tables had parent child relationship and were accessed using 2 pages. In this activity, we will design a single page to access all the three tables. Once the page is functional, use PeopleCode debugger to examine the sequence in which data is loaded into buffer. 2.4: Understanding PeopleCode Language

This topic will cover following areas

Data Types Comments Assignment Statements Language Constructs Functions Expressions Variables Operators

PeopleCode
Data Types

Any - When variables and function return values are declared as Any, the data type is indeterminate, enabling PeopleTools to determine the appropriate type of value based on context. Undeclared local variables are Any by default.

Boolean Date DateTime Float Integer Number Object String Time

Note. The Float and Integer data types should be used instead of Number only where a performance analysis indicates that the increased speed is useful and an application analysis indicates that the different representations won't affect the results of the computations. Comments Comments help to explain the code. They are also used to differentiate between PeopleCode delivered with the product and PeopleCode that you add or change. This differentiation helps in your analysis for debugging and upgrades. Note. Use comments to place a unique identifier marking any changes or enhancements that you have made to a PeopleSoft application. This makes it possible for you to search for all the changes you have made. This is particularly helpful when you are upgrading a database. There are three ways to include comments in the code. You can surround comments with /* at the beginning and */ at the end. You can also use a REM (remark) statement for commenting. Put a semicolon at the end of a REM comment. If you do not, everything up to the end of the next statement is treated as part of the comment.

PeopleCode
To enclose one set of comments within another set, use the symbol <* at the start and *> at the end. You generally use this when you're testing code and want to comment out a section that already contains comments. An example of usage as given in PeopleBooks is given below: <* this program is no longer valid REM This is an example of commenting PeopleCode; /* ----- Logic for Compensation Change ----- */ /* Recalculate compensation change for next row. Next row is based on prior value of EFFDT. */ calc_next_compchg(&OLDDT, EFFSEQ, 0); /* Recalculate compensation change for current row and next row. Next row is based on new value of EFFDT. */ calc_comp_change(EFFDT, EFFSEQ, COMP_FREQUENCY, COMPRATE, CHANGE_AMT, CHANGE_PCT); calc_next_compchg(EFFDT, EFFSEQ, 0); *> Statements A PeopleCode program is made up of statements. A statement can be: A declaration of variables or objects. An assignment. A program construct (such as a Warning statement or a conditional loop). A function call. A comment. Every PeopleCode statement should end in a semicolon. Separators PeopleCode statements are generally terminated with a semicolon. The PeopleCode language accepts semicolons even if theyre not required, such as after the last statement completed within an If statement. This enables you to consistently add semicolons after each statement.

PeopleCode
Extra spaces are ignored. They are removed by the PeopleCode Editor when you save the code. Assignment Statements The assignment statement is the most basic type of statement in PeopleCode. It consists of an equal sign with a variable name on the left and an expression on the right. Assign a value in PeopleCode by setting a field, or variable, or object equal to another field, variable, object property, or expression Syntax: fieldName = <fieldName>|&<variable>|<property>|<constant>|<expression>; &variable = <fieldName>|&<variable>|<property>|<constant>|<expression>; &object.property = <fieldName>|&<variable>|<property>|<constant>|<expression>; The expression on the right is evaluated, and the result is placed in the variable named on the left. Depending on the data types involved, the assignment is passed either by value or by reference. Assignment by Value In most types of assignments, the result of the right-hand expression is assigned to the variable as a newly created value, in the variable's own allocated memory area. Subsequent changes to the value of that variable have no effect on any other data. Assignment by Reference When both sides of an assignment statement are object variables, the result of the assignment is not to create a copy of the object in a unique memory location and assign it to the variable. Instead, the variable points to the object's memory location. Additional variables can point to the same object location. In the following example, &O1 and &O2 refer to the same object. The assignment of &O1 to &O2 does not allocate any database memory or copy any part of the original object. It makes &O2 refer to the same object to which &O1 refers. Local Array of Number &O1, &O2; &O1 = CreateArray(1, 2, 3);

PeopleCode
&O2 = &O1; Note. In PeopleCode, the equal sign can function as either an assignment operator or a comparison operator, depending on context. PeopleCode uses the standard mathematical operators

Several different mathematical operations can be performed using date and time fields

Language Constructs PeopleCode language constructs include:

Branching structures: If and Evaluate. Loops and conditional loops: For, Repeat, and While. Break, Continue, and Exit statements loop control and terminating programs. The Return statement for returning from functions. Variable and function declaration statements: Global, Local, and Component for variables, and Declare Function for functions.

PeopleCode
The Function statement for defining functions. Class definition statements. Try, Catch, and Throw statements for error handling.

If-Then-Else Construct PeopleCode uses a standard If-Then-Else construct for branching. Syntax: If condition Then <PeopleCode statement(s)>; [Else <PeopleCode statement(s)>;] End-If; Branching statements control the flow of execution based on the evaluation of a conditional expression. Every If statement must have a corresponding End-If to identify where the If statement ends. If statements can have three clauses: If Conditions Then Statements the Component Processor executes when the If clause is true Else Statements that execute when the If clause is not true (optional)

An If statement can also be more complex. There can be multiple conditions in the If clause, multiple statements in the Then clause, an Else clause, and nested If statements. Nested IF statements are an implied Boolean AND Error statements display a message to the operator and stop processing until the operator corrects the data and passes the error test. Syntax: Error "<message>"; Example: If All(BIRTHDATE) Then If BIRTHDATE > %Date Then Error Birthdate is after todays date; End-if; End-If;

PeopleCode

Warning statements displays a message to the user informing them that data may be invalid and allows them to decide whether or not to continue processing. Syntax: Warning "<message>"; Example: If All(JOB.ORIG_HIRE_DT, EMPLOYMENT.HIRE_DT) AND JOB.ORIG_HIRE_DT > EMPLOYMENT.HIRE_DT Then Warning Original Hire Date should not be after Hire Date.; End-if; Evaluate Statement When several different values of a field need to be analyzed, an Evaluate statement may be a more straightforward approach than a series of If statements. Syntax: Evaluate <field, variable, or expression> When = <expression1> When = <expression2> <PeopleCode statement(s)>; When = <expression3> <PeopleCode statement(s)>; When-Other <PeopleCode statement(s)>; End-Evaluate; In an Evaluate statement, one field or variable is evaluated for all possible values. Every Evaluate statement must end with an End-Evaluate clause. Evaluate statements have four clauses, with the When-Other being optional: Evaluate The field or variable PeopleCode should evaluate. When One for each possible value. Values can be referenced more than once. When-Other What PeopleCode should perform when the field or variable isnt any of the values specified in the When clauses. (optional) End-Evaluate An Evaluate statement can have unlimited When clauses.

PeopleCode
Multiple When clauses with no code between them act as an implied Boolean OR. Example: Evaluate field When = 1 When = 2 statement1; When = 3 statement2; End-Evaluate; A Break statement causes the program to terminate the Evaluate statement. In an Evaluate statement, PeopleCode always examines each When clause, even after a match is found. If the values in the different When clauses can never be true at the same time, processing time can be saved by terminating the Evaluate statement and moving to the next PeopleCode statement following the end of the statement when a match is found. This can be accomplished with a Break statement. Performance Tip: Evaluate the most likely conditions in WHEN clauses first, so once they are evaluated, the break statement can exit the evaluate and not spend time evaluating the less likely conditions. Example: Evaluate field When = "1" When = "2" statement; Break; When = "3" statement; Break; When-Other statement; End-Evaluate;

PeopleCode
Explaining Looping Statements There are three types of looping statements in PeopleCode: While loop Repeat-Until loop For loop A While loop continues to loop as long as the logical_expression evaluates to True. Multiple conditions can be incorporated using Boolean logic. A While loop performs a conditional logic check at the beginning of the loop, so it is possible the loop will not execute even once if the condition is False. Syntax: While <logical_expression> statement; statement; End-While; A Repeat-Until loop executes until the logical_expression evaluates to True. Because the condition is tested at the end of the loop, the loop will always execute at least once if it is invoked. Syntax: Repeat statement_list Until logical_expression; Whats the difference between While and Repeat-Until? When would you use which? A While is useful if its possible that the loop would never execute (zero or more times). A Repeat-Until is useful when you want the loop to execute at least once upon each invocation. In general these are a little more flexible than For loops since the logical check can be any Boolean expression, rather than being constrained to checking against an incremented number.

PeopleCode
A For loop will execute specific number of times, based on start, end and step values. A For looping statement is terminated with an End-For clause. Syntax: For <&variable> = <start-value> To <end-value> [Step <stepValue>] statement; statement; End-For; 2.5: Discussing Events in Detail

Each processing sequence is associated with one or more events that can be invoked during its flow. Each event is also associated with one or more Application Designer definitions. An event and definition combination identifies a unique PeopleCode program. Search Events The diagram below shows the execution point of the two search related events SearchInit and SearchSave events:

SearchInit Event SearchInit PeopleCode is performed before the search page is displayed. Use SearchInit to control processing before a user enters values in the search page. Place SearchInit PeopleCode on search key fields or alternate search key fields on a search record or component search record. Do not place errors or warnings in SearchInit.

PeopleCode
SearchInit for a search page is similar to RowInit for an application page

For example, the following program in SearchInit PeopleCode on the component search key record field EMPLID sets the search key page field to the users employee ID, makes the page field unavailable for entry, and enables the user to modify the users own data in the component: EMPLID = %EmployeeId; Gray (EMPLID); AllowEmplIdChg(true); Note: %EmployeeId provides the employee id of the operator using the system. We will learn about built-in functions and variables in day 3 of the PeopleCode class. The SetSearchDialogBehavior function can be called in SearchInit PeopleCode to set the behavior of search and add dialog pages before they are displayed, thereby overriding default behavior of the Component Processor. There are two settings: skip, if possible (0) and force display (1). SearchSave Event SearchSave PeopleCode is performed after the user clicks the Search button or the Add button on the search page. Use SearchSave to validate values entered in the search page fields. Place SearchSave PeopleCode on search key fields or alternate search key fields on a search record or component search record. Use Error and Warning statements to validate search page fields: o Error statements in SearchSave display an error message and prevent the search process from continuing. o Warning statements halt processing and allow the user to either continue or cancel.

PeopleCode

If a user tries to add a user ID that contains a space, or tries to add the user ID PPLSOFT, this program will generate an error. If they try to enter a user ID that contains a comma they get a warning.

Use the following navigation path to access this page:

The User Profiles search page is used to add a new user profile or update an existing user profile.

PeopleCode

SearchSave ONLY executes when you click the Add button or the Search button. It does NOT execute when the user selects an item from the returned search list. If the developer wants to check for something after the user selects an item from the returned search list, the first opportunity to do it is RowSelect or PreBuild. The more efficient choice is PreBuild. Activity 6 Watching Search events In this activity, students will place win message to identify the sequencing and execution of search events. 1. Open Component <STU_INITIALS>_COMPANY. Open the record associated with this component. 2. Add the following code under SearchInit Component Integer &C; &C = &C + 1; WinMessage("SearchInit on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " |<STU_INITIALS>_COMPANY.COMPANY | " C = " | &C); 3. Add the following code under SearchSave Component Integer &C; &C = &C + 1; WinMessage("SearchSave on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " |

PeopleCode
<STU_INITIALS>_COMPANY.COMPANY | " C = " | &C); 4. Save and validate the code 5. Watch the execution from PIA 6. Put breakpoints and watch the execution. Also examine the buffers Activity 7 Add a SearchSave code to <STU_INITIALS>_PERSONAL Add a code to SearchSave which checks if the field <STU_INITIALS>_EMPLID is blank. In case it is blank, issue a warning asking the user to give a value. Use Message Catalog to display messages. Component build events The component builds and page display events are: RowSelect PreBuild FieldDefault FieldFormula RowInit PostBuild Activate

PeopleCode

RowSelect Event RowSelect has been retained to maintain compatibility with old code, but do not use it in new code. o Instead, use a search view, an effective-dated record, the Select method, ScrollSelect or a related function, to filter rows. RowSelect can be used to control what rows are loaded into the component buffer. o o Prevent a row from loading by using the DiscardRow function. Stop loading rows into the buffer by using the StopFetching function.

RowSelect PeopleCode is placed on a record field or component record. Warnings and errors can be placed in RowSelect but will not be displayed to the user and are not used for that purpose in this event.

Example This RowSelect program filters rows based on whether the user has accessed the Earnings Balances component or the Special Balances component in the Human Resources application.

PeopleCode

PreBuild Event PreBuild executes only once during the component build process. PreBuild is often used to hide or unhide pages. It can be used to set global or component scope variables. PreBuild can only be placed on the component. Do not place errors or warnings in PreBuild.

This PreBuild program populates the OPRDEFNDESC field if it is empty

If a PreBuild PeopleCode program issues an error, the end-user is returned to the search page. If the program issues a warning statement, the component is cancelled. If there is no search page, that is, the search record has no keys; the component is cancelled for both error and warning statements. It is very rare to code errors or warnings in PreBuild since the user has not had an opportunity to interact with the component, unless the developer wants to check for

PeopleCode
something after the user selects an item from the returned search list, the first opportunity to do it is RowSelect or PreBuild. The better choice is PreBuild. Many PeopleCode events activate processing over which a user has no direct control. If the Component Processor came across an error condition, the user could not fix it. Therefore, Error and Warning statements should not be used in these PeopleCode events. That way, the Component Processor only encounters errors issued by PeopleCode when it cannot perform a task FieldDefault Event FieldDefault PeopleCode is applied only to blank fields. FieldDefault PeopleCode must be placed on the field upon which the default is to be applied. FieldDefault PeopleCode can be associated with record fields and component record fields. Do not place errors or warnings in FieldDefault. Note. You cannot use errors or warnings from FieldDefault PeopleCode. They cause a runtime error. A record field should not have both FieldDefault PeopleCode and a record default associated with it. Otherwise, the FieldDefault code would never execute, since record defaults are applied before FieldDefault PeopleCode in the Component Processor Flow Example: This FieldDefault program populates the Description field, DESCR, with the process name, PRCSNAME, but only if the Description field is blank.

PeopleCode
FieldFormula Event FieldFormula has significant performance overhead because it always processes. FieldFormula PeopleCode is placed on a record field. It is currently used only for function libraries and web libraries. Do not place errors or warnings in FieldFormula except within a function.

FieldFormula carries with it significant performance overhead because it always processes. In the flow of the Component Processor, every user action except Save applies FieldFormula PeopleCode before the page is displayed again. PeopleSoft has moved most of our code out of FieldFormula and into other PeopleCode events. This has improved performance in many applications by preventing unnecessary processing. As a matter of convention, FieldFormula is now often used in FUNCLIB_ (function library) record definitions to store shared functions. However, you can store shared functions in any PeopleCode event. FieldFormula PeopleCode is only associated with record fields. Sample record which contains function libraries

PeopleCode
Sample Code in fucntional libraries

RowInit Event RowInit PeopleCode is used to control the initial appearance of fields or to calculate values. It is performed the first time the Component Processor encounters a row of data. RowInit PeopleCode is placed on a record field or component record. Do not place errors or warnings in RowInit. Once for every row at the level where it is attached when the page is first displayed in Search mode Once just for the new row when a row is inserted (including the new row that is automatically inserted after the last row is deleted from a scroll.) Once on the row representing the search key in Add mode In certain rare circumstances, the Component Processor does not run RowInit PeopleCode for some record fields. It runs RowInit PeopleCode when it loads the record from the database. However, in some cases, the record can be initialized entirely from the keys for the component. When this happens, RowInit PeopleCode is not run. Example This RowInit program disables the address fields on the Students, Personal Details page if their address is the same as the customers

PeopleCode

PostBuild Event PostBuild PeopleCode is usually used to calculate values and set display characteristics of a page or page control. PostBuild PeopleCode executes only once during component build. Code that would otherwise be placed in the RowInit event is often placed in PostBuild because it occurs only once, while RowInit code executes once for every row. Do not place errors or warnings in PostBuild PostBuild PeopleCode is only associated with components.

Example This PostBuild program sets some component-level (panelgroup) variables and sets some display characteristics in the Security User Maintenance component.

PeopleCode

Activate Event Activate is the only event in the Page event set. The Activate event fires every time the page is activated (receives focus). Use the Activate event to segregate PeopleCode related to a specific page. Put PeopleCode related to page display or page processing, such as enabling a field or hiding a scroll, in this event. Use this event for security validation. Do not place errors or warnings in Activate.

You can write PeopleCode related to page display or page processing, such as enabling a field or hiding a scroll area, in this event. You can also write code that controls the security to this page in this event. Activate PeopleCode can only be associated with pages. This event is valid only for pages that are defined as standard or secondary. This event is not supported for subpages.

PeopleCode
Example This Activate program sets the grid labels for the User Profiles, Roles page.

The Activate event fires every time the page is activated (receives focus). This is defined as when the page is initially displayed, or if an end-user navigates between different pages in a component or launches a secondary page from within a components page. The Activate event effectively eliminates the need to write page-specific, record-level RowInit code. Note that the Component Processor builds a page grid one row at a time. Because the Grid class applies to a complete grid, you cant attach PeopleCode that uses the Grid class to events that occur before the grid is built. The first time that the entire grid is available for instantiation is in this event. Activity 8 Watching Component Build events In this activity, students will place win message to identify the sequencing and execution of component build event. 1. Open Component <STU_INITIALS>_COMPANY. Open the record associated with this component. 2. Add the following code under RowInit Component Integer &C; &C = &C + 1;

PeopleCode
WinMessage("RowInit on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " | <STU_INITIALS>_COMPANY.COMPANY | " C = " | &C); 3. Add the following code under PreBuild Component Integer &C; &C = &C + 1; WinMessage("PreBuild on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " | <STU_INITIALS>_COMPANY.COMPANY | " C = " | &C); 4. Save and validate the code 5. Watch the execution from PIA. Observe the sequence and number of times code gets executed. 6. Put breakpoints and watch the execution. Also examine the buffers

Activity 9 Watching Activate event 1. Open the page <STU_INITIALS>_COMPANY in App Designer, right click on the page and click on Page Peoplecode. 2. Write code to change the property of the field to display only when the user has entered in Update/Display mode. 3. Save the Peoplecode and open the page through PIA and see the effect of the code that you have just written.

PeopleCode
Field Action Events FieldEdit and FieldChange

FieldEdit Event FieldEdit is performed: o o After a field has changed. After the new value of the field has satisfied the standard system edits.

Use FieldEdit to validate the contents of a single field. This event executes only on the specific field and row that just changed. Assignment statements should not be performed in FieldEdit. FieldEdit PeopleCode is placed on a record field or component record field. Use Error and Warning statements in FieldEdit to prompt the user to enter valid data in the field. FieldEdit PeopleCode can be associated with record fields and component record fields.

PeopleCode
Example This FieldEdit program enforces the business rule that a GPA cannot be higher than 4.0

Activity 10 Using FieldEdit event Write PeopleCode to check whether the length of the data entered for country field in the COMPANY table is 3 characters in length. If no, then prompt a message saying that the Company must be three characters in length. As <STU_INITIALS>_COUNTRY is not a required field on <STU_INITIALS>_COMPANY_TBL, run this validation code only if there is a value in the Contry field. Use Error and warning to understand the difference. Try both the options and see the change in behavior. FieldChange Event FieldChange PeopleCode executes: o o o field. If FieldChange finishes successfully, the Component Processor displays the page, incorporating any visual changes. FieldChange PeopleCode is placed on a record field or a component record field. Do not place errors or warnings in FieldChange After a field has changed. After the new value of the field has satisfied the standard system edits. After FieldEdit PeopleCode has completed successfully.

It is used to perform additional processing based on the new value of a changed

Example This FieldChange program conditionally changes the Enabled property of the address fields to True or False based on the value of the SAME_ADDR_CUSTOMER checkbox

PeopleCode

Row Action Events RowInsert and RowDelete

PeopleCode
RowInsert Event RowInsert PeopleCode is performed when a new row of data is inserted within a scroll area. It can be used to override effective-dated processing, or to auto number new rows of data. Whenever a new row is inserted, RowInit PeopleCode is also performed. RowInsert PeopleCode is placed on a record field or a component record. Do not place errors or warnings in RowInsert. Do not write PeopleCode in RowInsert that already exists in RowInit, because a RowInit event always triggers after the RowInsert event, which will cause your code to be run twice. The RowInsert event triggers PeopleCode on any field on the inserted row of data. Usually a newly inserted effective-dated row is a copy of the current row with a new effective date. However, you dont always want all fields to be copied. For instance, you may not want a comment field to be carried over. In that case, you can clear or modify the contents of that field in this event You cannot conditionally prevent a row insert using the RowInsert event, but you can unconditionally prevent an insert into a scroll. In the page definition, Use properties tab, a scroll area or grid page control can be set to No Row Insert. A user can view and update information, but cannot insert rows of data Example This RowInsert program renumbers the rows in the scroll area when a row is inserted. When a new line is inserted, PeopleCode finds the highest existing line number, increments it, and assigns it to the new line. This code demonstrates the use of a looping construct in the case where the code is attached at the same level as the data it is processing in the component buffer. However, RowInsert executes against the newly inserted row only. A looping construct is required to determine the highest existing line number in the scroll and to calculate the new one, since a user can insert a new row anywhere in the scroll.

PeopleCode

RowDelete Event RowDelete executes when a user deletes a row of data. RowDelete can be used to calculate running totals, or to prevent a row from being deleted. Fields can be referenced on the deleted row until the Component Processor removes the row from its buffers. RowDelete PeopleCode is placed on a record field or a component record. Error statements prevent a row from being deleted. Warning statements allow the user to accept the Row Delete (OK), or cancel the Row Delete (Cancel). The RowDelete event triggers PeopleCode on any field on the row of data that is being flagged as deleted. Always remember that: When the last row of a scroll area is deleted, a new, dummy row is automatically added. Example This RowDelete program renumbers the remaining lines after a row is deleted

PeopleCode

You unconditionally prevent row deletions by setting the No Row Deletes in the page field properties of a scroll area or grid page control (in the Use tab). After RowDelete finishes, the Component Processor goes through FieldDefault and FieldFormula PeopleCode. Activity 12 Watching Row Action events In this activity, students will place win message to identify the sequencing and execution of component build event. 1. Open Component <STU_INITIALS>_COMPANY. Open the record associated with this component. 2. Add the following code under RowInsert Component Integer &C; &C = &C + 1; WinMessage("RowInsert on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " | <STU_INITIALS>_COMPANY.COMPANY | " C = " | &C); 3. Add the following code under RowDelete Component Integer &C; &C = &C + 1; WinMessage("RowDelete on COMPONENT.<STU_INITIALS>_COMPANY, <STU_INITIALS>_COMPANY " | <STU_INITIALS>_COMPANY.COMPANY | " C = " | &C);

PeopleCode

4. Save and validate the code 5. Watch the execution from PIA. 6. Put breakpoints and watch the execution. Also examine the buffers

PeopleCode
Save Action Events SaveEdit SavePreChange WorkFlow SavePostChange

SaveEdit Event SaveEdit PeopleCode is performed when the user tries to save the component. It is used to validate data before it is updated on the database. Do not use SaveEdit to assign values to other fields in the component buffer; the event should only be used for validation. SaveEdit PeopleCode is applied to all rows of data on all pages in the component at the level where it is attached (except on rows marked for deletion). Use SaveEdit for a validation that references more than one field or row that can be updated in the component (such as, a consistency edit). SaveEdit PeopleCode is placed on a record field and component record. An error in SaveEdit prevents the Component Processor from saving any row of data.

PeopleCode
SaveEdit errors can happen anywhere on the page or component, on any row of data. In SaveEdit PeopleCode it is important to write very clear error and warning messages to help the user locate and correct the source of the error. With a SaveEdit warning, the Component Processor displays a message and presents the user with two choices: o o Example This SaveEdit program validates two fields, Start Date and End Date, to make sure the start date precedes the end date. OK accepts the data, overriding the warning and continuing the save process. Cancel aborts the save process

The Component Processor does not update the database for any row if one row has an error. Although the Component Processor displays an error message, it does not turn any field red. Therefore, in SaveEdit PeopleCode it is important to write very clear error and warning messages, since the data causing the error may appear on a different page within the same component or on a row of data not currently displayed. This can be done by concatenating the values of fields into the message, as shown below. Error ("The value exceeds the maximum on the row dated: " | EFFDT); With this error statement, the user knows what caused the error and can quickly scroll to the appropriate row. Without the value of effective date brought into the message, the user would have to examine each row to find the error. The field object method SetCursorPos can also be used to position the cursor in the appropriate field and row for correction.

PeopleCode
Activity 13 Using Save Edit Event 1. Write PeopleCode to validate whether field <STU_INITIALS>_COUNTRY on the <STU_INITIALS>_COMPANY page has a value entered and is equal to IND. If not, display an error message. Use Message Catalog to display the error. SavePreChange Event After SaveEdit completes successfully, the Component Processor applies SavePreChange PeopleCode. It provides one last chance to manipulate data before the database is updated. Based on the validated values entered into the component, fields can be calculated or display characteristics can be changed. Place SavePreChange PeopleCode on a record field, component record, or component. Do not place errors or warnings in SavePreChange

If SavePreChange runs successfully, a Workflow event is generated, and then the Component Processor issues appropriate Insert, Update, or Delete SQL statements. SavePreChange PeopleCode is not field-specific: it triggers PeopleCode on all fields and on all rows of data in the component buffer. Example This SavePreChange program assigns a unique order number to new purchase orders.

PeopleCode

Workflow Event The Workflow event segregates PeopleCode related to Workflow from the rest of the applications PeopleCode. Only PeopleCode related to Workflow should be in this PeopleCode event. Workflow PeopleCode is placed on a record field or a component. Do not place errors or warnings in Workflow.

SavePostChange Event SavePostChange executes after SavePreChange completes successfully and the Component Processor issues the SQL statements to update the database. This event is used to update data in tables that are not in the component buffers. SavePostChange PeopleCode is placed on a record field, component record, or a component. Do not place errors or warnings in SavePostChange. The system issues a SQL Commit statement after SavePostChange PeopleCode completes successfully.
Important! Never issue a SQL Commit or Rollback statement manually from within a SQLExec function.

PeopleCode
Example This SavePostChange program updates the address fields in the Student Table when address fields on the Customer Table have been changed.

Other Events ItemSelected Event The ItemSelected event is initiated whenever a user selects a menu item from a pop-up menu. This event, and all its associated PeopleCode, does not initiate if run from a component interface. ItemSelected PeopleCode is only associated with pop-up menu items. PrePopup Event The PrePopup event is initiated just before the display of a pop-up menu. This event is generally used to control the appearance of a pop-up menu. PrePopup PeopleCode can be associated with record fields and component record fields.

PeopleCode

2.6:

Understanding Add Mode Processing

When the user adds a new key instead of selecting an existing key, the component processor behaves as shown in this flow chart:

The Component Processor flow that weve examined so far works for Search mode processing (Update/Display, Update/Display All, and Correction). The flow changes for Add mode to reflect slightly different processing requirements. Search Processing in Add Mode Add mode search processing is more involved than Search mode processing. The system first performs default processing on the keys. RowInit PeopleCode is then run on the search page fields. After this processing, the search page is displayed. If the user changes one or more fields on the search page, field change processing occurs. This consists of applying system edits (PeopleSoft name format, reasonable date

PeopleCode
checking, and so on), and running FieldEdit and FieldChange PeopleCode. If the field has no value, record defaults or FieldDefault PeopleCode are then reapplied. SearchSave PeopleCode runs before the search key values are placed into the component buffer. Component Build Process in Add mode The Component Build process for Add mode is similar to the processing for Update and Display modes. However, the process is a little simpler for Add mode. In Search modes, the system brings each row of data into the buffer by applying RowSelect PeopleCode, if applicable. The Component Processor then applies defaults (System defaults and FieldDefault PeopleCode) and runs FieldFormula PeopleCode. Finally, for each row of data in the buffer, the Component Processor applies RowInit PeopleCode at the scroll or occurs level attached and displays the component. In Add modes, there is no existing data to bring into the buffer. Therefore, the initial loop in which the data is brought into the buffer and RowSelect PeopleCode is bypassed. Also, because there is only one row of data per scroll area on the component, RowInit runs only once for each scroll or occurs level

2.7:

Understanding Deferred Processing In interactive mode, every field change forces a trip to the server. In deferred processing mode, fewer events cause server trips. Deferred processing results in o o Improved server and network performance Improved user experience.

Every trip to the server takes time.

Deferred processing is the default mode for PeopleSoft 8.

PeopleCode

This table shows user interactions that cause a trip to the server. Note that only the first three items in the list are deferred in deferred processing mode.

Activity 14 Create A vendor Table and sync it with Personal Table In this a new table will be created to store Vendor information. All employees needs to be identified as vendors so that they can be reimbursed for official expenses. 1. Clone <STU_INITIALS>_PERSONAL as <STU_INITIALS>_VENDOR. 2. Add a new high level key <STU_INITIALS>_VENDOR_ID 3. Move <STU_INITIALS>_EMPLID below the key structure and make it a non key field. It should prompt on <STU_INITIALS>_PERSONAL 4. Add a new Yes/No checkbox field <STU_INITIALS>_SAME_ADDRESS. Default it to No 5. Create a page and component to access <STU_INITIALS>_VENDOR. 6. Check if the page is working 7. Now add some business logic validation so that a. Selecting the field Same Address will default the value of <STU_INITIALS>_ADDRESS and <STU_INITIALS>_PHONE on vendor table from PERSONAL table. The fields will become display only on Vendor page and cannot be updated by a user. (Hint: use FieldChange and RowInit).

b. Write a code so that whenever the address and or phone is changed at


PERSONAL page, it will go and update Vendor table if Same Address field is checked.

Você também pode gostar