Sunday, 29 August 2021

D 365 FO Form Data source field Lookup

The below code will help you to create a lookup method for the Form Level Datasource field.

1) go to Form Open the Datasource where you want to add the Lookup select the Field to expand the property under method go to Override method and then select lookup method.

2) After selecting that it will create a method and you can copy-paste the below code inside the method.

3) Change the Tabke and condition according to your requirements. (Here for the demo I'm using Customer details CustTable).


public void lookup(FormControl _formControl, str _filterStr)

            {

                Query                   query = new Query();

                QueryBuildDataSource    queryBuildDataSource;

                SysTableLookup          sysTableLookup;


                sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResProduct), _formControl);

                queryBuildDataSource = query.addDataSource(tableNum(EcoResProduct));

                                     queryBuildDataSource.addRange(ProductType).value(enum2Str(EcoResProductType::Service));


                sysTableLookup.addLookupField(fieldNum(EcoResProduct, Displayproductnumber));

                sysTableLookup.addLookupField(fieldNum(EcoResProduct, SearchName));

                sysTableLookup.addLookupField(fieldNum(EcoResProduct, ItemClassification));


                sysTableLookup.parmQuery(query);

                sysTableLookup.performFormLookup();

            }







Thanks

Keep Daxing :)

No comments: