Home / Questions / init() - form data source methods - in D365 F&O
Explanatory Question

init() - form data source methods - in D365 F&O

👁 312 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

The init() method is a standard method of a form data source, which is called when a form is opened after the implementation of the form init() method. This method helps create a data source query based on the data source properties.

Example

You have a custom form with a table named TrainingMaster. The table has an enum type field named TrainingType that has two values: Online and Classroom. The form should be opened with those records, where TrainingType is Online.

The code pattern should be as follows:


[DataSource]
class TrainingMaster
    {

        public void init()
        {
            super();
            this.query().dataSourceName("TrainingMaster")
            .addRange(fieldNum(TrainingMaster,TrainingType))
            .value(enum2Str(TrainingType::Online));
        }
    }