Skip to main content

Custom Populate Actions and the OnPopulate() Method

Custom Populate Actions and the OnPopulate() Method

For additional control over the generated data, you can define an OnPopulate() method. If an OnPopulate() method is defined, then the Populate() method calls it for each object it generates. The method is called after assigning values to the properties but before the object is saved to disk. Each call to the Populate() method results in a check for the existence of the OnPopulate() method and a call to OnPopulate() it for each object it generates.

This instance method is called by the Populate method after assigning values to properties but before the object is saved to disk. This method provides additional control over the generated data. If an OnPopulate() method exists, then the Populate method calls it for each object that it generates.

Its signature is:

Method OnPopulate() As %Status 
{
    // body of method here...
}
Note:

This is not a private method.

The method returns a %StatusOpens in a new tab code, where a failure status causes the instance being populated to be discarded.

For example, if you have a stream property, Memo, and wish to assign a value to it when populating, you can provide an OnPopulate() method:

Method OnPopulate() As %Status
{
    Do ..Memo.Write("Default value")
    QUIT $$$OK
}

You can override this method in subclasses of %Library.PopulateOpens in a new tab.

FeedbackOpens in a new tab