To achieve this you can write a function in a FieldFormula event that implement the algorithm to generate the unique sequence number for a given record. Then, you can basically use that function in RowInset (for example) or any other event as you want.
Below function is implemented in FieldFormula Event
/*This function will Increment and assign unique number to the SEQNBR field;
Input Parameter - Record Object (passed as reference)
This example assume that your record has a field called SEQNBR - (PeopleSoft delivered number field)
You can modify this function to pass your custom Number Field as well,
so that you don't need to assume SEQNBR is a field in the passing record*/
Function GenerateSeqNbr(&recName As Record)
Local integer &intMaxSeqNbr = 0;
Local integer &I, &intSeqNbr;
Local Rowset &RS = GetLevel0()(1).GetRowset(@("Scroll." | &recName.Name));
For &I = 1 To &RS.ActiveRowCount;
&intSeqNbr = &RS(&I).GetRecord(@("Record." | &recName.Name)).SEQNBR.Value;
If &intSeqNbr > &intMaxSeqNbr Then
&intMaxSeqNbr = &intSeqNbr;
End-If;
End-For;
&intSeqNbr = &intMaxSeqNbr + 1;
&recName.SEQNBR.Value = &intSeqNbr;
End-Function;
/* To call the function*/ Declare Function GenerateSeqNbr PeopleCode MY_DRV_RECORD.SEQNBR FieldFormula; /*call the GenerateSeqNbr function for the current record from calling event*/ GenerateSeqNbr(GetRecord());
delivered functions: GetNextNumber,GetNextNumberWithGaps and GetNextNumberWithGapsCommit.
ReplyDeleteAnonymous 24 July 2015 at 06:54: Those are useful functions too.
ReplyDeleteWhat if the seqnum is on level 2. How do you tell the level 2 which level 1 row you are on?
ReplyDelete