Please do post your comments and suggestions for me to improve on chowdary1105@gmail.com

Sunday, August 9, 2009

Inserting a New Scroll Row from within the Same Scroll

In PeopleCode, when inserting or deleting a row on a scroll, it is required that you perform the action on a parent row of the rowset being inserted/deleted to. PeopleTools doesn’t allow PeopleCode (using the built-in functions/methods InsertRow and DeleteRow) to insert or delete a row on the same scroll within which it is currently running. If you attempt to do this, PeopleTools will give an error complaining about changing the current program context.

However, there are some cases where inserting within the same scroll might be desirable. For example, based on the data entered on a row of a scroll, a new matching row must be inserted within the same scroll.

Background

The Rowset class has a SelectNew method, which is quite similar to the Select method. The main difference is that rows populated through SelectNew are marked as new in the component buffer. Both Select and SelectNew allows the record source of the data being loaded to the rowset to be different from the primary record of the rowset. There is a requirement, however, that the source record must contain at least one of the key fields in the primary record. Though, none of the fields in the source record have to be keys as well.
The Technique

Step 1. Create a new Dynamic View record containing at least one of the keys of the primary record of the scroll. For this tutorial, assume that the name of the new record is SCROLL_INS_ROW. This is important: none of the fields in this record must be set to a key.

Step 2. Set the SQL of the view to the following:


SELECT NULL
FROM PS_INSTALLATION

Of course, if you’ve included more fields, then SELECT the appropriate number of NULL’s on the SQL.

Step 3. The PeopleCode for inserting a row within the same scroll would be the following:


Local Rowset &this_rowset = GetRowset();
&this_rowset.SelectNew(Record.SCROLL_INS_ROW);

No comments: