CurrentRowNumber function in Peoplecode

Our end user reported a peculiar error on one of the custom pages developed long ago. The structure of the page is shown below.

The “Override” hyperlink redirects to a secondary page where users may enter an override reason. This user was able to use the Override link on first row. But, when they use the Override link on second or third or further rows, they receive an error that states – “Invalid Row number”.

Its almost like Peoplecode yelling back – “I don’t know anything about the row you are talking about”. But, the row is right there in front of our eyes, without which the user cannot click the Override link.

The Override link is attached to APP_RSN_WRK.OVERRIDE record field. The Fieldchange peoplecode behind the rec field is:

&TRANS_ROW = GetLevel0()(1).GetRowset(Scroll.APP_TRANS).GetRow(CurrentRowNumber());


For &I_LOOP = 1 To &REASON_ROWSET.ActiveRowCount

   &WK2_REC = & REASON_ROWSET(&I_LOOP).GetRecord(Record. APP_RSN_WRK);

   If &WK2_REC.OVERRIDE_RULE.Value = "Y" Then
                    TICKER_ID = :2 AND TICKER_LINE_NUM = :3 AND TICKER_CNTRL_ID = :4 AND 

      If All(&REASONDESCR) Then

The error message occurs on the very first line of code. Why?

Lets dissect the code and analyze each part.

From the picture above, it becomes evident that the code errors out only when “GetRow(CurrentRowNumber())” returns an invalid row number.

Peoplebooks’ definition of CurrentRowNumber is:

This function can determine the current row number on the level where the function call resides, or on a higher scroll level. It won’t work on a scroll level below the one where the PeopleCode program resides.

CurrentRowNumber takes an optional number parameter. The parameter is a

A Number specifying the scroll level from which the function returns the current row number. If the level parameter is omitted, it defaults to the scroll level where the function call resides.

In our code, CurrentRowNumber doesn’t accept any function, therefore it will return the row number of the scroll from which the peoplecode event is executed.

Since the peoplecode is located in FieldChange event of “Override” link, which is located in Level 2 rowset, when the user clicks the link on third row, CurrentRowNumber() returns 3.

But is there a third row on the level 1 APP_TRANS rowset? NO!. Thats the problem. In other words, the CurrentRowNumber() and GetRow() functions are operating on two different scroll levels. Any moment, the level 2 scroll has more rows than the level 1 scroll, the error is bound to occur.

To rectify the same, the first line has to be replaced as

&TRANS_ROW = GetLevel0()(1).GetRowset(Scroll.APP_TRANS).GetRow(CurrentRowNumber(1));

Note the parameter value in CurrentRowNumber. Value of 1 forces the function to fetch the rownumber from Level 1 Rowset. That solved the error 🙂