RowInit Event
The RowInit event is initiated the first time that the Component Processor encounters a row of data. Use it to set the initial state of component controls during component build processing and row insert processing. The RowInit event also occurs after a Select or SelectAll Rowset method, or a ScrollSelect or related function, is executed.
Note:
Generally, if none of the fields in the new row are changed after the row is inserted (either by a user pressing Alt+7 or programmatically) when the page is saved, the new row is not inserted into the database. However, if the ChangeOnInit rowset class property is set to False, you can set values for fields in a new row in RowInsert or RowInit PeopleCode, and the row will not be saved.
RowInit is not field-specific. It triggers PeopleCode on all fields and on all rows in the component buffer.
Do not use Error or Warning statements in RowInit PeopleCode. They cause a runtime error.
RowInit PeopleCode is often paired with FieldChange PeopleCode. In these RowInit/FieldChange pairs, the RowInit PeopleCode checks values in the component and initializes the state or value of page controls accordingly. FieldChange PeopleCode then rechecks the values in the component during page execution and resets the state or value of page controls.
For a simple example, suppose you have a derived/work field called PRODUCT, the value of which is always the product of page field A and page field B. When the component is initialized, use RowInit PeopleCode to initialize PRODUCT equal to A × B when the component starts up or when a new row is inserted. You could then attach FieldChange PeopleCode programs to both A and B, which also sets PRODUCT equal to A × B. Whenever a user changes the value of either A or B, PRODUCT is recalculated.
RowInit PeopleCode can be associated with record fields and component records.
RowInit Exceptions
In certain rare circumstances, the Component Processor does not run RowInit PeopleCode for some record fields. The Component Processor runs RowInit PeopleCode when it loads the record from the database. However, in some cases, the record can be initialized entirely from the keys for the component. When this happens, RowInit PeopleCode is not run.
For RowInit to not run, the following must all be True:
-
The record is at level zero.
-
Every record field that is present in the data buffers is also present in the keys for the component.
The Component Processor determines if the field is required by the component. In practice, this usually means that the field is associated with a page field, possibly hidden, for some page of the component. It could also mean that the field is referenced by some PeopleCode program that is attached to an event on some other field of the component.
-
Every record field that is present in the data buffers is display-only.
RowInit not running is not considered to be an error. The purpose of RowInit PeopleCode is to complete initialization of data on the row after it has been read from the database. Because the data in this special circumstance is coming from the keylist, it was already initialized correctly by whatever processing produced the keylist. More general initialization of the component should be done in PostBuild PeopleCode, not RowInit.