CurrentRowNumber function in Peoplecode
February 23, 2011 4 Comments
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()); &REASON_ROWSET = &VLN_ROW.GetRowset(Scroll.APP_REASON); For &I_LOOP = 1 To &REASON_ROWSET.ActiveRowCount & REASON_REC = & REASON_ROWSET(&I_LOOP).GetRecord(Record.VCHR_LOG_RULE); &WK2_REC = & REASON_ROWSET(&I_LOOP).GetRecord(Record. APP_RSN_WRK); &BUSINESS_UNIT = &REASON_REC.BUSINESS_UNIT.Value; &TICKER_ID = &REASON_REC.TICKER_ID.Value; &TICKER_LINE_NUM = &REASON_REC.TICKER_LINE_NUM.Value; &TICKER_CNTRL_ID = &REASON_REC.TICKER_CNTRL_ID.Value; &TICKER_RULE_ID = &REASON_REC.TICKER_RULE_ID.Value; If &WK2_REC.OVERRIDE_RULE.Value = "Y" Then SQLExec("SELECT REASONDESCR FROM PS_APP_RULE_OVRD WHERE BUSINESS_UNIT = :1 AND TICKER_ID = :2 AND TICKER_LINE_NUM = :3 AND TICKER_CNTRL_ID = :4 AND TICKER_RULE_ID = :5", &BUSINESS_UNIT, &VOUCHER_ID, & TICKER_LINE_NUM, &TICKER_CNTRL_ID, & TICKER_RULE_ID, &REASONDESCR); If All(&REASONDESCR) Then &WK2_REC.REASONDESCR.Value = &REASONDESCR; End-If; End-If; End-For;
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