How to override the lookup in D365

 When we Need To Override A Lookup Form?


-> I have a form named DeptForm.


-> In this form I have a data source called Departments having two fields(Dept_Id,Dept_Name).


->I would like to filter the lookup of the Dept_Id to ensure it only shows Emp_Name relating to the Dept_Name the user has already entered.


// Here is the code


[Form]

public class DeptForm extends FormRun

{



    [DataSource]

    class Departments

    {

        [DataField]

        class Dept_Id 

        {

            /// <summary>

            ///

            /// </summary>

            /// <param name = "_formControl"></param>

            /// <param name = "_filterStr"></param>

            public void lookup(FormControl _formControl, str _filterStr)

            {

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


                //Create a new query

                Query                   query = new Query();

                QueryBuildDataSource    queryBuildDataSource;

                QueryBuildRange         queryBuildRange;


                //Specify the name of the table the lookup should show data from.


                queryBuildDataSource = query.addDataSource(tableNum(Employees)); // it will show data from this employees table


                //Filter the data on the Dept_Name field on the Employees table. // it will filter the data based on the dept_name we select 


                queryBuildRange = queryBuildDataSource.addRange(fieldNum(Employees,Dept_Name));


                //Only show records where the Dept_Name field matches the value in


                //Departments.MakeId, on the currently selected record.


                queryBuildRange.value(queryValue(Departments.Dept_Name));


                //Specify which fields should be shown  in the lookup form.


                //  field returned is the first field referenced


                sysTableLookup.addLookupfield(fieldNum(Employees,Emp_Name));


                sysTableLookup.addLookupfield(fieldNum(Employees,Dept_Name));

               

 

                sysTableLookup.parmQuery(query);


                sysTableLookup.performFormLookup();


            }


        }


    }


Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O