Peoplecode Events Flow

PeopleCode Events. Page Display. Search Record. Save Processing. Popup Menu. Field Actions. Row Actions ©2001 PeopleSoft, Inc. A l rig hts reserved. Copies may be made only with the prior written consent of PeopleSoft. Rowinit is used to initialise the rows.Postbuild peoplecode performs after all the component build events have performed. Activate event is fired everytime the page is activated. Was this answer useful?

  1. Peoplecode Order Of Execution
  2. Peoplecode Events Flow Chart
  3. Peoplecode Events Flow With Examples

PeopleSoft PeopleCode

- An Introduction

Overview

If you are reading this, you are probably familiar with creating fields, records, pages, components, and menus. With these objects alone, you can create working development projects. Simple ones, yes, but these objects are all you need for the most basic level of development. PeopleCode comes into play for those development projects requiring a little more control. For example, you know how to define the default of a field within the record definition. This means that a value is always placed in this field whenever it is empty. But what if you needed to have a default placed in a field based on a condition of another field? You cannot do this within the record definition, but you can by using PeopleCode. The PeopleCode capability enables you to set and control a lot of parameters and objects. To fully understand the PeopleCode system and develop with it, you first need to learn about how it works.

PeopleCode is a visual language similar to Microsoft Access or Visual Basic. In fact, in PeopleTools version 8.1, the coding syntax has been changed to reflect the Visual Basic (called VB from here on) standard. This makes the PeopleCode language easier to use and learn for developers who already know VB or the Visual Basic for Applications (VBA) programming language.

The first detail to learn about PeopleCode is not the language itself but how the code works within the framework of PeopleSoft. PeopleCode can be placed in events on the field definition in each record. PeopleCode can also, since PeopleSoft 8.1, be placed into events on fields within pages and components. Each event is a place of action that launches PeopleCode when certain processes take place on a page.

Using events is a difficult concept to grasp at first and you might have to spend extra time to fully understand this process.

Understanding How PeopleCode Events Work

PeopleSoft comes with 17 events for PeopleCode. Each event has a specific function and control for which it is designed.

PeopleSoft Panel Processor

PeopleCode does not just run whenever it feels like it. Each event has a specific time when it runs within the PeopleSoft process. The PeopleSoft process is controlled by the internal PeopleTools program, which is called the PeopleSoft Panel Processor . The PeopleSoft Panel Processor is the control program within PeopleSoft that is monitoring the user's actions. This program controls when the PeopleCode will activate as well as a lot of other things based on the user's actions.

Event Order

To best understand the PeopleSoft Panel Processor, consider the process of starting and running a page to see when all the types of events are going to run.

First, the user selects from the menu to run a specific page in a certain action (this action being Add, Update/Display, Update/Display All, or Correction). The Panel Processor then looks at the menu selection to find the component connected with it. The component contains the search record for the action in which the user has asked the system to run. The search record keys, alternate keys, and list information are gathered from the search record that has been assigned to the component. The search page is created online with the keys and alternate keys displayed for entry, but before the user can enter any data, the first event of PeopleCode activates.

After this code is complete, the user is able to interact with the search page to search records and select the one they wish to process. Upon clicking OK in this search panel, the next event becomes active.

SearchSave

If no error messages are encountered within the code, the main page, as requested from the menu by the user, is now opened. Data, as selected from the search page, is then ready to be loaded into the page. Before the data is actually loaded, each row of data that is to be loaded onto the page is validated by the code contained in the next event.

The page is now filled with data from the search page, but the processor is not yet ready for user input. A series of events must launch for each row of data already loaded into the page.

FieldDefault FieldFormula RowInit

Each one of these events runs, in order, on all rows of data within the page. After all these events run, and if no errors have occurred, the page is open for entry by the user, finally. But this is only the beginning of what PeopleCode can do. Now, depending on the action of the user, more PeopleCode may activate.

If the user changes a field (modifies or deletes) or adds data to an empty field, the following PeopleCode events run. Of course, the standard PeopleSoft record edits must pass first, such as the prompt values as defined in the record definition for this field.

If the user inserts a new row of data on a page (only for occurs levels 1 through 3), then the following PeopleCode events run for all the fields on the record that is within the level where the add was performed. To better explain, if the insert was done on level 2, then only the PeopleCode events on the record definitions contained within level 2 are activated. The PeopleCode events within the record definition on levels 0 or 1 are not activated.

RowInsert FieldDefault FieldFormula

If the user deletes a row of data on a level 1 through 3 scroll, then the following PeopleCode events run for the row deleted and then for all the rows that are left within the level where the delete occurred.

The last step the user can take is to save the page. The save process runs another set of PeopleCode events, as listed below.

SaveEdit SavePreChg Workflow SavePostChg

As you can see, the PeopleCode events activate based on certain actions requested by the user, such as starting a page, changing data, or inserting new rows.

You will also note that some events of PeopleCode are running a lot of the time. You need to understand the flow of the events so that when you have a function or code to add to the system, you place the code in the correct event and therefore it runs at the appropriate time to perform the correct action. You can place code in an incorrect event so that it runs too much—this will affect your system by slowing it down.

Using PeopleCode Events

This section teaches you about each event, providing examples of use including actual PeopleCode. Developers already familiar with PeopleCode will see the same events but there are some new things to learn as well - these are fully discussed in the 'New to Version 8.1' section below.

SearchInit

The code in the SearchInit event is needed only for records that will be used as search records. If the record definition you have is not used as a search record, then code placed in here will never run.

Code placed in this event is typically used to set up default values on the search page. For example, this event is mostly used to set up counters or defaults from the operator preferences on the search panel. For example:

SetSearchEdit(BUSINESS_UNIT);

SetSearchDefault(BUSINESS_UNIT);

This example turns on edits and system defaults for the Business Unit field in the search page. This code does not cause any other PeopleCode category to activate; it simply sets up the information in the page object to be used in that specific field.

SearchSave

This code also applies to the search page and is typically used to validate the search page to make sure all the required fields are filled in. Because you cannot specify the required fields on a search record (the record definition's required attribute is for use only on the regular pages), you can place code here to do the validation of all the fields that must be filled in. For example:

If None(BUSINESS_UNIT) Then

Error MsgGet(9000, 3, 'Business Unit is a required field.');

End-If;

check_status(BUSINESS_UNIT, PO_ID, &STATUS);

If &STATUS = 'C' Or &STATUS = 'X' Then

Error MsgGet(10200, 164, 'The specified PO exists, and is either Completed or Cancelled.');

End-If;

check_auto_num(BUSINESS_UNIT, &AUTO_NUM);

If None(&AUTO_NUM) Then

Error MsgGet(10000, 1, '%1 is not a Purchasing business unit.', BUSINESS_UNIT);

End-If;

If &AUTO_NUM = 'N' And PO_ID = 'NEXT' Then

Error MsgGet(10200, 34, 'This business unit is not set up for purchase order auto numbering.');

End-If;

This example shows a little more about the capability of this event of code. The code here, although complex for now basically checks that certain fields are filled in. If they are filled in, then the data is validated for specific conditions. If an error condition exists, an error message is displayed and the search page is not closed.

RowInit

Now you have arrived at events that are used more often in development projects. The code in the RowInit event runs every time a new row of data loads into a page. This section activates code for each level and each data row. For example, if you have a panel with a level 1 that has 15 data rows that load, the RowInit event will run 16 times: once for the level 0 (header information) and then 15 times for each row of data on level 1.

You need to understand that even though on the page you can see only five rows of data, this code activates for all rows of data that are loaded into the buffer. So it is not how many rows are visible on the page, but how many rows are loaded into the data buffer that determines how many times this PeopleCode category activates. Consider the following 3 examples:

If %PanelGroup = PANELGROUP.VCHR_PO_STD Then

If All(PO_ID) Then

VCHR_PANELS_WRK.TXN_CURRENCY_SRC = 'P';

End-If;

End-If;

If INSTALLATION.PO = 'Y' Then

DERIVED.EDITTABLE13 = 'ITM_PURCH_FS';

End-If;

Gray(LINE_NBR);

Gray(SCHED_NBR);

Gray(BUSINESS_UNIT_RECV);

These examples show different ways to use the RowInit event that are typically done. The first example shows, based on some information, that you can set some values into special fields. The second example shows that you can also set or change the prompts used. Finally, the third example shows how you can override the settings on the page to hide, gray (display-only), unhide, or ungray (not display-only) fields based on the initialization.

FieldDefault

In this event, field defaults can be coded. This event works only to set defaults into fields where the logic is too complex to use the record definition. If, by contrast, you have a hard default that is always to be used, then you should set that value in the record definition. Otherwise, you can set the default based on a condition check of some other field or value using code from the FieldDefault event. For example:

If None(ITM_SETID) Then ITM_SETID = GetSetId('BUSINESS_UNIT', BUSINESS_UNIT, 'MASTER_ITEM_TBL', '); End-If;

This example checks whether the ITM_SETID field is filled in. If the field is not filled in, then the code runs a function to get the information and place it in this field.

FieldChange

The FieldChange event occurs under two circumstances: once when a field is changed, and the other when a button is pressed.

For the field change event, the code does not execute unless there is a net change (changing the value of a field to it's original value is not a net change) and the user moves out of the field or saves the page. Here you can do very complex validation upon the field.

Example: If VENDOR_ITM_VW1.ITM_STATUS = 'A' Then If PRICE_DT_TYPE = 'P' And QTY_TYPE = 'L' Then check_line(); Else check_schedules(); End-If;

This example checks the values in a couple of fields and then, based on their settings, runs a different function. In the FieldChange event, you are not limited to using only the field from which the code is launched, but rather, you can access any field on the page as is shown in this example.

You can also use the FieldChange event when you have a button on a panel; here you would place the code that you wish to activate when the button is pressed. The code you place for a button can be just about anything you want. This is what makes button actions so powerful—they can perform all sorts of actions, controls, and verifications. When you have a button and it is pressed, you are usually looking for some action to take place: jump to another panel, fill in the current panel with data based on some criteria you have set, or run a process, for example.

UnhideScroll(RECORD.PO_LINE);

UnGray(GOTO_LINE_DTLS);

SEL_LINE_FLG = 'Y';

LINES_SAVED = 'N';

&WHERE = 'where BUSINESS_UNIT = :1 and PO_ID = :2 and LINE_NBR >= :3';

If All(LINE_NBR_TO) Then

&WHERE = &WHERE | ' and LINE_NBR <= :4';

End-If;

ScrollFlush(RECORD.PO_LINE);

ScrollSelect(1, RECORD.PO_LINE, RECORD.PO_LINE, &WHERE, PO_HDR.BUSINESS_UNIT, PO_HDR.PO_ID, LINE_NBR_FROM, LINE_NBR_TO, True);

This example is from a button which, when pressed, is going to fill in data based on some criteria. The scroll, on level 1 in the panel, is un-hidden (now visible on the panel), and the data buffer is emptied for this scroll (scroll flush). Finally, the scroll's data buffer is filled with data based on a selection criterion.

FieldEdit

In the FieldEdit event, you apply most of the field editing to validate information within a field. You already can do one simple validation using the prompts on a field as defined within the record definition, but this event gives you the ability to validate using multiple fields and conditions. This is also the event to apply messages from PeopleCode that will not crash the panel, to warn or stop the process within the page.

The FieldEdit event is where you should place validation that you want to occur within the page field entry process. If you have validations for which you do not want to leave the field before a specific criteria or process is complete, then you need to place code in FieldEdit. In this event, the action is based only on the field you are in, so be careful not to validate against another field that you cannot change. If you do validate against another field, you will be locked in a loop and you won't be able to leave this field.

To better explain this potential loop problem, assume that you have two fields on a panel. The first field can be set to a value of Red or Blue only. The second field can be set to a number that represents the brightness of the color (that is, the first field). Now red can have a brightness only between 1 and 5, whereas blue can have a brightness between 3 and 9. So you place FieldEdit code in the first field (the color field) that states that if the value is blue, then the value of the second field must be between 1 and 5. This meets the logic requirement, but if you understand the FieldEdit process, you will see how this will get you into trouble. The user enters Red into the first field and tabs out to the next field. The PeopleSoft Panel Processor then runs the FieldEdit code for the field that states that if the value is red (which is what the user entered), then the value of the next field must be between 1 and 5. Because the user has not entered a value in the next field, the value is initialized as 0. Therefore, this FieldEdit code fails and requires the user to input a value that will not fail. Because you've allowed only red and blue, and neither is allowed to have a 0 value, then the user can never leave this field. This is a simple explanation, but it shows how you have to be careful when using FieldEdit code for validation using other fields. You have to understand the capabilities of the system and how the rules will be applied. In this example, the best solution is to change the location where the validation code is placed. The validation code should be placed in the Field Edit event of the brightness field, or it could be moved to the SaveEdit event (about which you have not learned yet).

The way that PeopleSoft will pass or fail a validation is by issuing a message. If you fail the validation, a message must be called. If you pass the validation, then no messages are displayed. There are two types of messages: warning and error. Each is a message, but they carry different levels of actions.

A warning message tells the user that they might not want to continue or to use this value in the field. With a warning message, the user can decide to stop and fix the issue or move on and ignore the message. A warning means that the value in this field is not normal, but the user is still allowed to continue. An error message , on the other hand, does not offer the user a choice; the user must stop and fix the problem. You should make sure that all decisions to error or warn are well documented in the technical documentation for your modification.

The following example shows how to use the FieldEdit to do complex validation with an error message. If a problem occurs, issue an error message to the user stating the problem and do not allow the process to continue until it is resolved.

check_item();

If None(PO_HDR.VENDOR_ID) Then

Error MsgGet(10200, 76, 'Vendor %1 is not set up for item %2.', PO_HDR.VENDOR_ID, INV_ITEM_ID);

End-if;

FieldFormula

This event is typically reserved for custom-built functions. You have already learned about the flow of how PeopleCode activates from the PeopleSoft Panel Processor and that the process FieldFormula runs for all sorts of actions. You should not place any code in this category except custom-built functions.

Consider the following example:

Function update_sched() &CHANGED_SCHED = 'N';

UpdateValue(LINE_NBR, &LINE, PO_LINE_SHIP.UNIT_PRC_TOL, &SCHED, &UNIT_PRC_TOL);

UpdateValue(LINE_NBR, &LINE, PO_LINE_SHIP.PCT_UNIT_PRC_TOL, &SCHED, &PCT_UNIT_PRC_TOL); End-Function;

This example shows a function that performs some actions. A function can take in multiple values and even send back values to the calling program. This enables you to write business logic into functions that many programs can call so that you do not have to write the logic over and over in multiple PeopleCode categories. This is important to PeopleCode 8.1 in that you now have the ability to place code in new places. By having more places—pages and components—in which to load PeopleCode, you need to remember that you may require the same code in multiple places or categories. Instead of copying the code into all these different places and events, you can create the one function and then call it from the other places, thereby having your logic in only one place. Due to this added complexity, you will need to think more in terms of functions when writing code. Writing more functions that you place into this event will save you time and effort in the long run.

RowSelect

This event is used to filter data loaded into a scroll level. This is an advanced technique that will not be covered in this book. Most developers who want to restrict rows of data create a view to use on the page with the restriction in the SQL where clause. By using this event, you can apply this restriction as you need to or you can even change the criteria as the page is being created.

RowDelete

This event is used to activate code when a delete is performed for a row of data rather than for only a single field. This delete can be on any level. The developer, when using this code even, can control whether a row of data can be deleted by checking for orphaned records or other required validations. The purpose of this code is to prevent deletes unless a specific criterion has been met.

The process to show the pass or fail of the event is just like in the FieldEdit event. If you failed the validation, pass a message. If you do not issue any messages, then the delete process has passed the validation. This category can also use the warning and error message commands: An error always fails; a warning reports an issue to the user.

If VOUCHER.POST_STATUS_AP = 'P' Then Error MsgGet(7030, 109, 'You cannot delete a voucher line if the voucher has been posted.'); End-If;

The code here checks a field for a specific status. If a certain status is set, then the code prevents the deletion by issuing an error message. If the status is not set, the code will allow the deletion by not issuing any error or warning message.

RowInsert

In the RowInsert event, you apply code to inserts of new data rows. Data, when loaded into the page, is validated through the RowInit event, but when you add a new record (level 0) or a new row of information (level 1 through 3), there is no RowInit to activate because it was not initiated into the panel. The RowInsert can and should perform the up-front validations that you would have placed in RowInit for new data rows being added.

Note

As you can see, you might need to place the same code in the RowInit and RowInsert categories. This is another reason for looking at code that you could place into functions so that you do not end up copying the same code into multiple categories.

If VCHR_PANELS_WRK.FULL_SET_FLG = 'Y' Then

MERCHANDISE_AMT = VCHR_PANELS_WRK.VCHR_BALANCE_AMT; VCHR_PANELS_WRK.LN_BALANCE_AMT = MERCHANDISE_AMT;

End-If;

This code checks a work record field for a specific status and then updates some fields using information in some other work record fields. The process done here can be just about anything you think of, from graying (display only) and hiding fields to doing complex logic for recalculating a total.

SaveEdit

In the SaveEdit event, you place code that validates on a save. This is used for the final validation of the record. Usually, you can do a lot of this validation in the FieldEdit event, but you might want the user to do all the input they can and then do a check just prior to the save. You might also have to validate multiple fields as a unit. It is hard to do this within FieldEdit, so you can place the overall validation in this event instead.

A final use for the SaveEdit event occurs when the user does not tab through every field so the FieldEdit code never activates. If you still need this validation, you will have to add it to SaveEdit to be sure that the code does run.

As with the other edit events, you can prevent or just warn on a save when the validation is incorrect. If you prevent, then the user is unable to save the panel. If you warn, then the user can stop the save process and edit the problem or they can continue. The process is the same regardless of whether you're using warning or error messages. Of course, no message means that you have passed the SaveEdit validation.

If DISTRIB_MTHD_FLG = 'Q' And None(QTY_VCHR) Then

Error MsgGet(7030, 49, 'You must enter either a quantity on Voucher Line %1 when distributing by quantity. Or you can delete the line.', VOUCHER_LINE_NUM);

Else

If None(MERCHANDISE_AMT) Then

Error MsgGet(7030, 49, 'You must enter either a merchandise amount on Voucher Line %1 when distributing by amount. Or you can delete the line.', VOUCHER_LINE_NUM);

End-If;

End-If

This code checks some values in the fields and then, if certain conditions exist, an error message is issued, preventing the save of this panel.

SavePreChange

In the SavePreChange event, you can place code to change or update the data tables prior to the save being committed to the database. This is your last chance to make changes. In your page, you are making changes, but these changes are loaded only into your panel buffers. It is not until you save the record that the database is updated. Once the save is started, the PeopleCode runs and does all its SaveEdit checks and then just prior to saving the information to the database, this event occurs. This event enables you to do other processes and update other rows of data, assuming that the process will complete.

The SavePreChange event, is used mostly to update hidden fields that need to be changed or corrected based on user input just prior to saving. You do not do updates within SaveEdit, as this is only supposed to be looking for errors. If you need to total a field in level 1 and place the information in a header record (level 0), here is where you would make the code work, since you do not want to update the header level field with every row insert or field change on the level 1. This enables you to put code in one place, and it runs doing the work just prior to the save.

Many developers will place SQLexec function calls in this category. SQLexec function calls enable you to run a SQL statement directly so that you can update a related field that is not within the page. You have to be aware that using SQL direct statements can lead you into trouble. You must be sure that the record you are going to update or insert is not any- where within the component. If any field of the record is on the component, then you will receive an error: This panel has been updated by another user . This error message is telling you that something happened to the data between the time you retrieved the data and the time you saved it. Someone else grabbed the information and changed it prior to your change committing it to the database. The problem occurred because of your SQLexec—it ran and made an update to the database. The PeopleSoft Panel Processor then tries to commit the rest of your changes and sees that someone else (yes, even though the SQLexec came from your process, the processor sees this as another user) has made a change, so your panel is not allowed to save. So be extra careful when using SQL calls within the events.

For &BUFFER_ROW = 1 To &CURRENT_ROW

UpdateValue(VOUCHER_ID, CurrentRowNumber(), DISTRIB_LINE.DESCR, &BUFFER_ROW, DESCR);

End-For;

This code loops through all the rows of a level 1 panel and updates a value in a lower-level scroll (level 2).

SavePostChange

In the SavePostChange event, you add code that you want to activate after the rows of data have been saved to the database. Code placed here could be line totals and other calculated fields. This is also where a lot of SQL execs are written and performed to update other necessary fields.

If %Mode = 'A' and VENDOR.VENDOR_PERSISTENCE = 'O' Then

&SETID = GetSetId('BUSINESS_UNIT', BUSINESS_UNIT, 'VENDOR', ');

SQLExec('Update ps_vendor set VENDOR_STATUS = 'I' where setid = :1 and vendor_id = :2', &SETID, VENDOR_ID)

End-If;

This code example shows that if the page is in Add mode and the vendor is set to a special persistence, then the vendor status must be set back to inactive so that no further POs can be used. This process is used on vendors that are set to one time use only. After you use them on a PO , the status is set to inactive so that you do not use them again. You can see in this example how you are updating the vendor based on an action in the PO system.

Workflow

The workflow event is for the specific use of workflow. You need to put in specific code here that updates the workflow records and processes. Workflow is beyond the scope of this book.

New for Version 8.1

With the release of PeopleTools 8.1, PeopleSoft has made some major changes to the PeopleCode system. You are now able to place code not only within the record definition, but you can also place code in the page, component, Application Engine, and Business Components. This means that you have more places to enter code to meet your development needs. These new capabilities are explained in this section.

Note

Application Engine and Business Components are specialized, advanced tools that are not covered in this book. They are mentioned here so that you know about all the new places to locate PeopleCode, but no further mention will be made.

The process of PeopleCode running on the system has already been mentioned, but what happens when PeopleCode is encountered within the new areas such as pages and components? Well, the same overall order still applies. For example, when a scroll level has data loaded into it, the RowInit code runs for each row of data. Now you are only adding a new level of complexity to RowInit: first, all the RowInit code runs from the record definition, then all the page code RowInit activates, and finally the RowInit code in the component area runs. So the overall flow of the code running through the events stays the same, but now you have some new areas to run within each event.

Let's explore each new section of PeopleCode within the page and component, reviewing why they would be used and what events are available.

PeopleCode in Pages

Why would you place code in a page versus a record definition? If you have code for a RowInit-type function that you wish to have run only when you are accessing a specific page, then you should place code in that page. This way, you do not need to write code to retrieve the page name and then check whether you need to run this code.

This requirement to have code run when within a specific page is used all the time, because if you include one field from a record, all the PeopleCode of the record loads into the page and runs. You might have a page that is usually used for this record and you hide this field until a specific action is done. Now, when you are in the other panel, the code will run, but this field does not exist on the page because it is for a whole different process. You would have had to retrieve a value for the page you are in to then see whether you wish to run the code.

Now with the new capability in PeopleSoft 8.1, you can place code directly into the page so that it will activate only when the page is accessed.

The event here is a new name called Activate. Although it is a new name, you can swap it for RowInit. This is the only event available for the page; the code entered here is associated with the page itself.

PeopleCode in Components

Because you could place code only in the Activate event within the panel, there was still a need to place code so that it runs only when a specific page is running. PeopleSoft tools developers created a new place to load PeopleCode within the component to solve this problem. You now have access to many more events that run only when in a specific component.

Within the component definition, you have access to the following events:

Peoplecode Events Flow

SearchInit

SearchSave

RowInit

RowSelect

RowInsert

RowDelete

SaveEdit

SavePreChange

SavePostChange

FieldChange

FieldDefault

PreBuild

PostBuild

SavePreChange

SavePostChange

Workflow

FieldEdit

As you can see from the list, you have all the events—including two new ones: PreBuild and PostBuild. The order of the events and how they activate is not changed within the component. Having this new capability enables you to enter code into the component so that the code will run only when this component is active.

Remembering the rule requiring all the PeopleCode of a record to be loaded, even when using only one field on a page, let's see how you can save time and effort by using this new capability. Instead of having to write code to check what component you are in for every piece of PeopleCode you have in the record definition, you can place just the right amount of code within the component PeopleCode events. This makes the PeopleCode easier to write and much more efficient.

Usually, you enter all the PeopleCode into the record and field definition area, but now you can enter the code into the component. Using the component PeopleCode events, it gets a little more complex. You can enter code against the component itself, fields within the component and, finally, records within the component.

PreBuild

The PreBuild event is specific to the component; this code runs prior to the component being built. This is typically used to hide, unhide, gray, or ungray fields, or to set certain values in the component.

PeopleCode within the component record gives you an opportunity to set variables that can be used later by PeopleCode located in other events. PreBuild can also be used to validate data in the search page just as is done in the SearchSave event. This event runs right after the RowSelect event within the flow of PeopleCode.

PostBuild

The PostBuild event is specific to the component; this code runs after the component is built. This is usually used to hide, unhide, gray, or ungray fields, or to set certain values in the component. The event can be thought of just like the RowInit event as the data is already loaded into the component. This even runs right after the RowInit even in the PeopleCode flow.

The Component Processor is the PeopleTools runtime engine that controls processing of the application from the time the end-user requests a component from an application menu through the time that the database is updated and processing of the component is complete.
How does the component processor allocate buffers to hold data?
The component processor starts allocating buffers at occurs level 0 and then works its way down. It uses the page and record definitions to determine the data it needs. Generally, if there is one field from the record definition on the page, the entire row will be brought into the buffers. The exceptions are fields that are in the search dialog box, derived work fields, and related display fields.
How to access the Peoplecode Debugger?
Peoplecode debugger can be used through Application designer. Open the program. Choose Debug, Enter Debug mode. The local variables watch window opens.
Choose, Debug, View Component buffers. The component buffer pane opens. We can view visible current line of execution, visible breakpoints. We can also place the cursor on the fields to see their current value.
What is Win-message built in function?
The Win-message built in function can also be used for debugging. It is used to display an information message to the user without performing error and warning processing.
What is people code trace?
Peoplecode Trace can also be used for debugging. To turn on the trace, go to PeopleTools, Utilities, Debug, Trace Peoplecode. We can see number of check boxes to set the detail level of the trace. As we select a combination of check boxes and click on Save, the system starts creating the trace file. Add &Trace=y to your browser’s URL. All the trace setting options will appear on login page. Using the Configuration Manager select the check boxes and select Apply. Then log off Peoplesoft and log back to start the trace.
How many data types we have in people code?
The conventional data types available in previous releases are the core of PeopleCode functionality. The object data types are used to instantiate objects from the PeopleTools classes. The appropriate use of each data type is demonstrated where the documentation discusses PeopleCode that uses that data type.
PeopleSoft recommends that you declare your variables before you use them.
· Conventional data types.
Conventional Data Types
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.
· DATE
· FLOAT
Note. The FLOAT and INTEGER data types should be used 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.
· OBJECT
· TIME
For most classes in PeopleTools, you need a corresponding object data type to instantiate objects from that class.
· Field
· Row
The following are the page display types:
· GridColumn
The following are the Internet Script types:
· Request
The following are the miscellaneous object types:
· Array
· Interlink
Note. BIDocs and Interlink objects used in PeopleCode programs run on the application server can only be declared as type Local. You can declare Interlinks as Global only in an Application Engine program
Note. JavaObject objects can only be declared as type Local.
· OptEngine
· SoapDoc
· SyncServer
Note. TransformData objects can only be declared as type Local
· XmlDoc
Note. XmlNode objects can only be declared as type Local.
API Object Type
The API object type has some additional considerations.
Use this data type for any API object, such as a session object, a tree object, a Component Interface, a PortalRegistry, and so on.
The following ApiObject data type objects can be declared as Global:
· PSMessages collection
· All Tree classes (trees, tree structures, nodes, levels, and so on.)
All other ApiObject data type objects must be declared as Local .
How many types of variables are there in peoplecode?
local
component
What is the scope of variables, local, global, component, derived work field, system?
Local: local variables created automatically by assigning a value to the variable. We can declare anywhere with in a people code program
Global variables: To use these variables we must declare it at the beginning of the program. Once declared it can be referenced the operator logs off peoplesoft. Only comments or other declarations are allowed top of these declaration. These variables should be used to transfer values between components only.
At what time system varaiable are created?
System variables are automatically created when an operator logs on to peoplesoft.
Where we can declare variables?
PeopleCode supports the 2 types of functions:
Declaration is not at all required for built-in functions, and we can call directly.
Built-in functions are divided into different types based on their purpose.
We have 3 types of User-Defined Functions.
Internal PeopleCode Functions: Peoplecode common routines contained within the same program where they are used. These functions are defined by the Function statement. Declaration is not at all required for Internal PeopleCode Functions. Internal PeopleCode Functions are defined within the program from which program we are calling the function.
External PeopleCode Functions: Peoplecode functions contained in a different program from where they are used. These functions are defined by the Declare… Peoplecode statement in the programs where used. Declaration is required to call this function. External PeopleCode functions are defined outside the calling program. Most External PeopleCode functions are stored on record definitions called function libraries.
External non-PeopleCode Functions: Common routines written in C or another language and loaded from a DLL. These are defined by the PeopleCode Declare… Library statement. Declaration is required to call this function, External non-PeopleCode Functions are stored in external libraries. And the convention is, place the all external functions in the Field Formula Event
How you declare a function?
Internal peoplecode functions: In this peoplecode identifies function by the Function statement.Each function must end with a corresponding End-function
Syntax: Function (,…………)
Statement
External peoplecode functions: By using Declare function statement at the beginning of the program.
Syntax: Declare function peoplecode field formula;
The keyword peoplecode identify the function as an external peoplecode function. Once an external people code function is declared in a program it can then be called multiple times.
External Non peoplecode functions: A common c++ routine that is loaded from a DLL. It defines by a Declare statement with the keyword library.
What is a Rowset, row, record, field object?
Rowset: It is a data structure used to describe hierarchical data. It is made up of a collection of rows. It can contain all of the scroll’s data. A level 0 rowset contains all the data for the entire component. A rowset contains one or more rows. A rowset can contain the entire contents of a Component Buffer, or the contents of any lower level scroll plus all of its subordinate buffer data.
Row: Row represents a single row in a component scroll. A row contains one or more records or child rowsets.
Record: Record is a single instance of data within a row and is based on a record definition. A record contains one or more fields.
Field: Field is a single instance of data within records and is based on a field definition.
What is a class and an object?
A class is the formal definition of an object and acts as a template from which an instance of an object is created at runtime. The class defines the properties of the object and the methods used to control the object’s behavior. PeopleSoft delivers predefined classes (such as Array, File, Field, SQL, and so on.) You can create your own classes using the Application Class.
An object is a data structure in the memory. An instance of an object is created from its class.
In how many ways an object can be instantiated?
Createxxx built in functions- create an empty data structure in the data buffer.
Getxxx built-in functions- creates a data structure that refer to already existing data in the buffer.
Getxxx methods- Create a child object of the parent object executing the method.
What is SQLExec?
The SQLExec function executes a SQL command from within a PeopleCode program by passing a SQL command string. We can use SQLExec with insert, delete, update commands to modify data in tables that have not been loaded into the component buffer. If you want to delete, insert, or update a single record, use the corresponding PeopleCode record object method.
If you want to delete, insert, or update a series of records, all of the same type, use the CreateSQL or GetSQL functions then the Execute SQL object method.
SQLExeccan only SELECT a single row of data. If your SQL statement (or your SQL.sqlname statement) retrieves more than one row of data, SQLExec sends only the first row to its output variables. Any subsequent rows are discarded. This means if you want to fetch only a single row, SQLExec can perform better than the other SQL functions, because only a single row is fetched. Another limitation is that PeopleTools won’t maintain quoted literals. It means if any changes are made to definitions that are referenced in a SQLExec quoted literal, Peoplesoft cannot apply the changes to the code. If you need to SELECT multiple rows of data, we can use SQL class. First a SQL object has to be instantiated using the CreateSQL built-in function
SQLExec statements that result in a database update (specifically, UPDATE, INSERT, and DELETE) can only be issued in the following events:
SavePreChange, WorkFlow, SavePostChange, FieldChange
Remember that SQLExec UPDATEs, INSERTs, and DELETEs go directly to the database server, not to the Component Processor (although SQLExec can look at data in the buffer using bind variables included in the SQL string). If a SQLExec assumes that the database has been updated based on changes made in the component, that SQLExec can be issued only in the SavePostChange event, because before SavePostChange none of the changes made to page data has actually been written back to the database.
Syntax: Local SQL &SQL (declaring the SQL object from SQL class)
What is the fetch method?
The fetch method can be used to retrieve the next row from the cursor. Fetch takes as its argument the output variables to receive values from the Select.
What is SQLdefinition?
SQL definition- A SQL definition is an Application Designer definition that is used to store and maintain a SQL statement. We can create the SQL definition using the application designer and edit the SQL in SQL editor. Benefits of SQL definition- Reusable, Upgradeable, platform independent, Validated.
To reference a SQL definition, you will instantiate a SQL object with the GetSQL built-in function.
SQL.sqlname is the name you gave the definition when it was saved.
Use CreateSQL(“SQL string”) when you are passing a text string to your SQL object.
Use GetSQL (SQL.sqlname) when you are getting the SQL from a SQL definition.
In which peoplecode events we can place SQLExec updates, deletes and inserts?
SavePreChange
SavePostChange
Peoplecode Events:
SearchInit– This event is performed before the search page is displayed to the user. It’s a way to control processing before the user enters any value in the search page. Placed on search record field or component search record.
SearchSave- This event is performed when the user clicks on the search button in the search dialog. Error and warning messages can be placed on this event to prompt the user to enter at least one value in the search dialog. Placed on the search record or component search record.
RowSelect- This event is performed as the component processor reads data into the buffer. This peoplecode can prevent the component processor to load any specific data into the component by using the DiscardRow and StopFetching functions. Placed on record field or component record.
PreBuild- This event is performed once before the rest of the component build events. It can be used to hide or unhide pages and to set component variables. It can also be used to validate data entered in the search page. Placed on a component.
FieldDefault- This event is performed when a field has no value. It is used to set the default value to the field. Placed on record field or component record.
FieldFormula- After the FieldDefault is performed successfully, FieldFormula is performed. But it increases the performance overhead as it processes unconditionally every time the page is displayed. Now this event is used to store the web function libraries. Placed on a record field.
RowInit- This event is performed for every new row encountered by the component buffer. It is used to control the initial appearance of the fields. Placed on record field or component record.
PostBuild- This is performed after the component processor builds the page and before the page is displayed to the user. It is used to hide or unhide pages and set component variables. Placed only on the component.
Activate- This is performed when the page is displayed to the user. This is the only page event. It occurs each time the user selects a page. Placed on a page.
FieldEdit- This is performed once the value of the field is changed and the new value satisfies the system edits. It is used to validate the new value of the field. Error and warning messages can be placed. Placed on record field or component record.
FieldChange- After the FieldEdit is performed successfully, this event is performed but it is not used for validation. It is used for any additional processing based on the new value of the changed field. Placed on record field or component record.
RowInsert- This is performed when the user inserts a new row in the scroll. Placed on record field or component record.
RowDelete- It occurs when a row is deleted from the scroll. Error and warning messages can be placed to prevent the user to delete any row. Placed on record field or component record.
SaveEdit- It is performed once the user tries to save the component. It is used to validate data before it is updated on the database. This applies to all the rows of data and all pages in the component. Placed on record field and component record.
SavePreChange- It occurs after the SaveEdit is performed successfully. It provides one last chance to manipulate data before the database is updated. Placed on record field, component record or component.
WorkFlow- It occurs when a component is saved. Use Workflow to trigger a business event. Workflow PeopleCode is not field-specific: it triggers PeopleCode on all fields and on all rows of data in the component buffer. Placed on record field, component record or a component.
SavePostChange- After SavePreChange completes successfully, and the component processor issues the SQL statement to update the database, SavePostChange peoplecode is applied. It occurs after the system updates the database. Code in this event is used to update the data not in the buffer but in the database. Placed on record field, component record or component.
ItemSelected- The ItemSelected event fires whenever the end-user selects a menu item from a pop-up menu. In pop-up menus ItemSelected PeopleCode executes in the context of the page field from where the pop-up menu is attached, which means that you can freely reference and change page fields, just as you could from a pushbutton. This event and all its associated peoplecode will not fire if run from a component interface.
ItemSelected PeopleCode is only associated with pop-up menu items.
PrePopup- The PrePopup event fires just before the display of a pop-up menu.
You can use PrePopup PeopleCode to control the appearance of the Pop-up menu. This event and all its associated peoplecode will not fire if run from a component interface.
PrePopup PeopleCode can be associated with record fields and component record fields
Record Field
Component Record
Page
FieldChange
FieldEdit
PrePopup
RowInit
RowSelect
SavePostChg
SearchInit
Workflow
FieldDefault
PrePopup
RowInit
RowSelect
SavePostChg
SearchInit
PostBuild
SavePostChg
Workflow
ItemSele
What are message events?
These events are not considered part of the Component Processor flow, so they’re documented separately from the majority of PeopleCode events. The following events are associated with messages:
· OnSubscribeTransform Event
· OnRouteReceive Event
In a message definition, you can associate a PeopleCode program with the message itself and with each message subscription included in the definition.
Sequence of events firing:
Field level default processing:
Field formula
Search processing in update Mode:
Search Save
Row init
Field Edit
Save Edit
Row select
Row init
Activate
Component Build processing in Add Mode:
Post build
Save edit
Workflow
Row insert
Post build
Field Modification process:
Field change

Peoplecode Order Of Execution

Row select processing:
Row delete
Popup menu display:
Prepopup
Difference between Field Edit and Field Change?
We can write error messages in field edit and we can not write in field change.
Differenct between prebuild and postbuild?
Prebuild: The PreBuild event fires before the rest of the component build events. This event is often used to hide or unhide pages. It’s also used to set component variables. The PreBuild event is also used to validate data entered in the search dialog, after a prompt list is displayed
Post Build : The PostBuild event fires after all the other component build events have fired. This event is often used to hide or unhide pages. It’s also used to set component variables.
It provides one last chance to manipulate data before the database is updated.
It occurs after the system updates the database. By using this event we can update the data directly in the database.
To restrict some users to insert new rows into scrolls. It is valid only if the component is having scrolls (means child records). The program never executes unless there is scrolls, not valid for 0 level records.
Push button- Push buttons are used to trigger peoplecode programs. The advantage is that the user determines when the program should be performed by clicking on the push button. A push button will perform any FieldEdit and FieldChange events where the push button is attached.
The component processor flow changes for which events in add mode?
Traversing the data buffer- Accessing specific data by working through the data buffer hierarchy is known as traversing the data buffer. We can traverse the data buffer from the top down, starting from level 0 rowset and working the way down to a specific field.
Component Rowset &RS_level0, &RS_level1;
Component Record &Record;
Step 2: Get the level 0 rowset and level 0 row
&Row_level0 = &RS_level0.GetRow(1);
&RS_level1 = &Row_level0.GetRowset(SCROLL.Empl_Checklist);
&Row_level1 = &RS_level1.GetRow(2);
&Record = &Row_level1.GetRecord(Record.Empl_Checklist);
&Field = &Record.GetField(Field.Briefing_status);
Rowset &RS_level0 = Getlevel0();
Rowset &RS_level1 = &Row_level0.GetRowset(SCROLL.Empl_Checklist);
Row &Row_level1 = &RS_level1(&I);
Rowset &RS_level2 = &Row_level1.GetRowset(SCROLL.Empl.Chklst_Itm);
Row &Row_level2 = &RS_level2(&J);
Field &Field = &Record.Briefing_status;
End For;
&Field = GetLevel0() (1).Empl.Checklist(1).Empl_Chklst_Itm(1).Empl_Chklst_Itm.Briefing_status;
Suppose you want to access the BRIEFING_STATUS field at level 2 of the following page:
The first thing to ask is where is your code running? Where are you starting from? For this example, the code is starting at a field on a record at level 0. However, you do not always have to start at level 0.
After you start with level 0, you must traverse the data hierarchy, through the level 1 rowset, to the level 2 rowset, before you can access the record that contains the field. Here’s the hierarchy again:
A rowset contains one or more rows, a row contains one or more records and zero or more child rowsets, and a record contains one or more fields.
Rowset
You first obtain the level 0 rowset, which is the PERSONAL_DATA rowset. However, you do not need to know the name of the level 0 rowset to access it.
&LEVEL0 = GetLevel0();
The next object to get is a row. As this code is working with data that is loaded from a page, there will only ever be one row at level 0. However, if you have rowsets that are populated with data that is not based on Component Buffers (for example, an Application Message) you may have more than one row at level 0.
&LEVEL0_ROW = &LEVEL0(1);
Rows Can Contain Child Rowsets
We need to get to the level 2 rowset. To do that, we need to traverse through the level 1 rowset first. Therefore, the next object we want to get is the level 1 rowset.
&LEVEL1 = &LEVEL0_ROW.GetRowset(SCROLL.EMPL_CHECKLIST);
Rowsets Contain Rows
If you’re traversing a page, the first thing to always do after you get a rowset is to get the appropriate row. Because we want to process all the rows of the rowset, we set this up in a loop.
For &I = 1 to &LEVEL1.ActiveRowCount
. . .
Rows Can Contain Child Rowsets, Rowsets Contain Rows
We need to traverse down another level in our page structure. This means accessing the second level rowset. Then we need to access the rows in the second level rowset, in another loop.
Because we’re processing all the rows at the level 1, we’re just adding code to the previous For loop. As we’re processing through all the rows at level 2, we’re adding a second For loop. The new code is in bold.
For &I = 1 to &LEVEL1.ActiveRowCount
&LEVEL2 = &LEVEL1_ROW.GetRowset(SCROLL.EMPL_CHKLST_ITM);
&LEVEL2_ROW = &LEVEL2(&J);
End-For;
Rows also contain records. In fact, a row will always contain a record, and may contain only a child rowset, depending on how your page is set up. GetRecord is the default method for a row, so all you have to specify is the record name.
Because we’re processing all the rows at the level 2, we’re just adding code to the previous For loops. The new code is in bold.
For &I = 1 to &LEVEL1.ActiveRowCount
&LEVEL2 = &LEVEL1_ROW.GetRowset(SCROLL.EMPL_CHKLST_ITM);
&LEVEL2_ROW = &LEVEL2(&J);
. . .
End-For;
Records Contain Fields
Records are made up of fields. GetField is the default method for a record, so all you have to specify is the field name.
Because we’re processing all the rows at the level 1, we’re just adding code to the previous For loops. The new code is in bold.
For &I = 1 to &LEVEL1.ActiveRowCount
&LEVEL2 = &LEVEL1_ROW.GetRowset(SCROLL.EMPL_CHKLST_ITM);
&LEVEL2_ROW = &LEVEL2(&J);
&FIELD = &RECORD.BRIEFING_STATUS;
End-For;
The previous code is the long way of accessing this field. What if you wanted to use all the shortcuts, and access the field in one line of code? Here it is! The following code assumes all rows are 1.
What is current context?
Referencing that portion of the data buffer on which a program is executing is referred to as current context. Most PeopleCode programs run in a current context. The current context determines which buffer fields can be contextually referenced from PeopleCode, and which row of data is the “current row” on each scroll level at the time a PeopleCode program is running.
Can we update the table, which is not in component buffer?
Data Buffer methods-
Sort method- Using the sort rowset method, it is possible to sort the rows within the rowset based on custom criteria.
&RowSet.Sort (, “A | D” [, “A | D”])
Select method- This method is used to select the rows into a rowset from the select record. The select method is used only with rowsets that reference the component buffers, instantiated using the GetRowSet method or function.
Syntax- &RowSet.Select (RECORD.selrecord, “where…” [,]);
Fill method- This method is used to fill the rowset which does not reference the component buffers. It is used with standalone rowsets instantiated using the CreateRowSet function.
Flush method- It is used to remove the rows from the buffer before using a Select to bring new rows in. It clears all the rows from the buffer without deleting them from the database.
What are think time functions? What are they?
Think time functions suspends action or processing until the user has taken some action.(such as clicking ok button in message box).
Do model
Exec (when synchronous)
Insert image
We should not write these functions in following events:
Workflow
Save postchange
What is the difference between functions and procedures?
Functions returns a value, procedures not return any value, package is the combination of functions and procedures
What is Data Buffer?
Component buffer contains active component data.
What data stores in Component buffer?
Only search record fields are available, If we put one non search key value in 0 level then all levels data will available.
Primary record fields are available
Derived work record placed on a component is available
Debugging in two-tier connections involves connecting directly to the database, not through the application server. Use this method to debug two-tier Windows applications.
Use three-tier debugging to debug three-tier Windows applications and PIA applications. For three-tier debugging, use PSADMIN to make sure that the following items are set.
· The appropriate PSDBGSRV Listener Port is specified in the PeopleCode Debugger section of PSADMIN.
· At least two PSAPPSRV processes configured to boot in the domain with the Service Timeout parameter set to 0 (zero).
· You indicate y for Yes at the “Enable PSDBGSRV Server Process” prompt at the end of the PSADMIN interface.
You set these parameters as you configure or create a domain
Hyde
Grey
Substring
All
Win message
Fetch value
%component
Setlable,
Row count
Field changed
is changed
prior value
create sql.
CreateRecord creates a freestanding record definition and its component set of field objects. The specified record must have been defined previously, that is, it must have a record definition. However, if you are calling this function from PeopleCode associated with a page, the record does not have to be included on the current page.
This function returns a record object that references a new record buffer and set of fields.
GetRecord creates a reference to a record object for the current context, that is, from the row containing the currently executing program. GetRecord returns a record object.
The following code:
Is equivalent to:
Or
What is CreateSQL and GetSQL and how they differ with SQL EXEC?
The GetSQL function instantiates a SQL object and associates it with the SQL definition specified by sqlname. The SQL definition must already exist, either created using PeopleSoft Application Designer or the StoreSQL function.
Processing of the SQL definition is the same as for a SQL statement created by the CreateSQL function.
The CreateSQL function instantiates a SQL object from the SQL class and opens it on the given sqlstring and input values. sqlstring is a PeopleCode string value giving the SQL statement.
Any errors in the SQL processing cause the PeopleCode program to be terminated with an error message.
You can use CreateSQL with no parameters to create an empty SQL object that can be used to assign properties before being populated and executed.
HOW WE ACESS THE DATA ON SECONDARY PAGE WHICH IS ON LEVEL 3?
WHAT IS THE IMPORTANCE OF ROWINIT, ROWSELECT & FIELD CHANGE? IS THERE ANY RELATION SHIP B/W THESE EVENTS?
HOW WE DISPLAY THE SECONDARY PAGE BY USING PEOPLECODE FUNTION
By using DoModel function we can display secondary page
HOW CAN WE OPEN DIFFERNET COMPONENT IN A NEW WINDOW BY CLICKING OF A HYPERLINK?
HOW WE KNOW WE ARE IN CURRENT PAGE?
IF WE ARE RUNNING AE PROGRAM THROUH ONLINE PAGE CAN WE USE COMPONENT BUFFER DATA IN AE PEOPLECODE?
IF AN ERROR OCCURS IN SAVE POST CHANGE PEOPLECODE WILL THE DATA MODIFIED BY THE USER IN COMPONENT BUFFER UPDATES IN DATABASE? WHY?
If there is same Component X in two different menus, menu1 and menu2 and if u want to assign a different search record for each menu, then which peoplecode function do u use and where do u write the code?
Explain with an example, where you used peoplecode extensively?

Peoplecode Events Flow Chart

What is File Clause?
Difference between component rec field events and record field events?
From Level 1 how can we access level 2 3rd row record field?
Can you assign values to a table, which is not in a Component Buffer?
How can you get a different component by clicking the hyperlink on a page? How can you open a different component in a new window by clicking on a hyperlink?
Tell me component buffer and scroll buffer functions
What is the scope of variables local global derived work field and system
Some Meta strings
If you are running AE through online page can you use component buffer data in ae peoplecode

Peoplecode Events Flow With Examples

Data mover commands