Sat 21 Apr 2007
Inserting a New Scroll Row from within the Same Scroll
Posted by ChiliJoe under PeopleSoft • Tips & Techniques • PeopleCodeIn 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.
March 4th, 2008 at 3:13 pm
Well, it’s a very good trick. Regarding limitation, you can sort the rowset.
May 19th, 2008 at 10:33 pm
Another neat titbit. Thanks
May 21st, 2008 at 3:47 pm
I avoided this error (changing the current program context) by working the scroll from the end to the beginning… It s very usefull with Component Interface collections too.
for &I = myrowset.rowcount to 1 step -1
…
end-for;
good blog! thanks
May 29th, 2008 at 2:51 pm
Hi Joe,
Thanks for the above Information…..
Can U please elaborate on this more like :After this do we need to access the above Rowset Object &this_rowset like the way we normally do…….
and also can u provide some information on Component Interface……..
(actually I am new to peoplesoft…..)
Keep the Good Work goin…..