Friday, October 4, 2024

Get lookup of All addresses by legal entity

Requirement: I had one Requirement where I wanted to filter the global addresses based on selected legal entity(Company). So by following below code we can get those addresses in lookup which are related to that specific legal entity.


[Form]

public class Form2 extends FormRun

{

    [Control("String")]

    class FormStringControl1

    {

        /// <summary>

        ///

        /// </summary>

        public void lookup()

        {

            Query query = new Query();

            QueryBuildDataSource queryBuildDataSource;

            QueryBuildRange queryBuildRange;

            CompanyInfo  companyInfo;

            OMInternalOrganization  oMInternalOrganization;

            DirOrganizationBase   dirOrganizationBase;

            DirPartyTable dirPartyTable;

            DirPartyLocation DirPartyLocation;

            LogisticsLocation   logisticsLocation;

            LogisticsPostalAddress  logisticsPostalAddress;


            companyInfo=CompanyInfo::findDataArea("USMF");


            select oMInternalOrganization where  oMInternalOrganization.RecId==companyInfo.RecId


                join dirOrganizationBase where dirOrganizationBase.RecId==oMInternalOrganization.RecId


                join  dirPartyTable    where dirPartyTable.RecId==dirOrganizationBase.RecId;



           

 

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

 

            sysTableLookup.addLookupField(fieldNum(LogisticsPostalAddress, Address));

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

            

            while select  DirPartyLocation where DirPartyLocation.Party==dirPartyTable.RecId


                join logisticsLocation where logisticsLocation.RecId==DirPartyLocation.Location


                join logisticsPostalAddress  where logisticsPostalAddress.Location==logisticsLocation.RecId

           

            {

          

               // Info(strFmt("%1",logisticsPostalAddress.Address));

 

                queryBuildRange = queryBuildDataSource.addRange(fieldNum(LogisticsPostalAddress, RecId));

                queryBuildRange.value(any2Str(logisticsPostalAddress.RecId));


            }

 

            sysTableLookup.parmQuery(query);

 

            sysTableLookup.performFormLookup();


        }


    }


}

No comments:

Post a Comment

Debug In D365fo with Tier 2 environment database

 Today in this blog we will see how to debug in d365fo with Tier2 env's(uat,gc,preprod) Step 1:-  Request JIT access  If you have LCS ac...