lookup() - Form data source field methods in D365 F&O - X++ Code
Answer:
The lookup()
method is a standard method on the field of the form data source. This method is called when a lookup operation is attempted on a data source field. If data that's shown in the lookup form must be customized with some filter, the lookup()
method should be overridden.
Example
You have a custom form with a table named TrainingMaster. The table has a field named TrainerID that creates a foreign key with the TrainerTable. TrainerTable has an enum field called TrainerType that has two values: Technical and Functional. The lookup in the TrainerID field should display only technical trainers.
The coding pattern can be as follows:
[DataSource] class TrainingMaster { [DataField] class TrainerID { public void lookup(FormControl _formControl, str _filterStr) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TrainerTable),_formControl); Query query = new Query(); QueryBuildDataSource qbds; qbds= query.addDataSource(tableNum(TrainerTable)); qbds.addRange(fieldNum(TrainerTable, TrainerType)).value(enum2Str(TrainerType::Technical)); sysTableLookup.addLookupfield(fieldNum(TrainerTable,TrainerID)); sysTableLookup.addLookupfield(fieldNum(TrainerTable,TrainerName)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } } }
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of X++ Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.