How to add subquery result in X++ FO D365

 If you want to add a subquery result in the lookup x++, Kindly follow the following steps;

1 - You have to create a temp table;

  TableTmp tableTmp;

2- Add all records of TableA in the temp table as show below;

      tableTmp.clear();

            while select TableA 

            {

                tableTmp.RequestId = TableA .RequestId;

                      tableTmp.doinsert();      

            }

3- Remove the record you don't need in the tempTable, Which exists in TableB as shown below;

    while select TableB

            {   

                select firstonly tableTmp where tableTmp.RequestId == TableB.RequestId;

                

                if(tableTmp )

                {

                    tableTmp .doDelete();

                }

            }

            select tableTmp ;

4- The complete code for the lookup field is shown below;


             TableA tableA ;

            TableB tableB ;

              TableTmp tableTmp;

            tableTmp.clear();

            while select tableA 

            {

                 tableTmp.RequestId = TableA .RequestId;

                      tableTmp.doinsert();   

            }


           while select TableB

            {   

                select firstonly tableTmp where tableTmp.RequestId == TableB.RequestId;

                

                if(tableTmp )

                {

                    tableTmp .doDelete();

                }

            }

            select tableTmp ;


            SysTableLookup   sysTableLookup = SysTableLookup::newParameters(tableNum(TableTmp ), this);

            Query                   query = new Query();

            QueryBuildDataSource    queryBuildDataSource;

            QueryBuildRange         queryBuildRange;


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


            queryBuildDataSource.addRange(fieldNum(TableTmp ,RequestId));


            sysTableLookup.addLookupfield(fieldNum(TableTmp , RequestId));

            sysTableLookup.parmTmpBuffer(tableTmp );

            sysTableLookup.parmQuery(query);

            sysTableLookup.performFormLookup();


Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2