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.

Yes, you can always make concessions, like forcing the user to click a button on a higher scroll level. Yet if you are looking for a way to insert within the same scroll level, read on. This tutorial illustrates a technique for doing a row insert from PeopleCode to the same scroll where the PeopleCode program is running.

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);

 

Additional Notes

It is not necessary to create a new source record for every scroll you wish to apply this technique to. It is possible to create a common record: just add additional fields to match one of the keys of the target scroll.

Limitations

Because this technique actually appends data to the rowset, the row is always inserted at the end of the scroll.