Thursday, August 10, 2023

Get Sales Order Address in Dynamics 365 F&O X++

 

Get Sales Order Address in dynamics 365 F&O X++


Scenario 1

LogisticsPostalAddress = LogisticsPostalAddress::findRecId(salesTable.DELIVERYPOSTALADDRESS);
        if(logisticsPostalAddress)
        {
            select RecId from logisticsLocation index hint
                LogisticsLocationIdx where logisticsLocation.RecId ==  logisticsPostalAddress.Location;

            select RecId from dirPartyLocation where dirPartyLocation.Location == logisticsLocation.RecId;
            
            SalesAddressContract = new SalesAddressContract();
            SalesAddressContract.parmAddressDescription(logisticsLocation.Description);
            SalesAddressContract.parmDeliveryAddressName(DIRPARTYTABLE::findRec(dirPartyLocation.Party).Name);
            SalesAddressContract.parmAddressStreet(logisticsPostalAddress.Street);
            SalesAddressContract.parmAddressCity(logisticsPostalAddress.City);
            SalesAddressContract.parmAddressState(logisticsPostalAddress.State);
            SalesAddressContract.parmAddressCountryRegionId(logisticsPostalAddress.CountryRegionId);
            SalesAddressContract.parmAddressZipCode(logisticsPostalAddress.ZipCode);
            SalesAddressContract.parmAddressCountryRegionId(logisticsPostalAddress.CountryRegionId);
            SalesAddressContract.parmsunTAFMarkForExtAddressCode(logisticsLocation.ExtAddressCode);// Custom field

            addressList.addEnd(SalesAddressContract);

        }

Scenario 2

Find phone and contact person in the contact information


public str  phonePersonName(SalesTable _salesTable)
    {
        LogisticsElectronicAddress electronicAddress;
        electronicAddress = DirParty::primaryElectronicAddress(CustTable::find(_salesTable.CustAccount).Party, LogisticsElectronicAddressMethodType::Phone);
        if (!electronicAddress)
        {
            electronicAddress = DirParty::getElectronicAddressForPartyPostalAddress(CustTable::find(_salesTable.CustAccount).Party, LogisticsElectronicAddressMethodType::Phone);
        }
        return  electronicAddress.Description;
    }
  display Phone phone()
    {
        LogisticsElectronicAddress electronicAddress;
        electronicAddress = DirParty::primaryElectronicAddress(this.Party, LogisticsElectronicAddressMethodType::Phone);
        if (!electronicAddress)
        {
            electronicAddress = DirParty::getElectronicAddressForPartyPostalAddress(this.Party, LogisticsElectronicAddressMethodType::Phone);
        }
        return electronicAddress ? electronicAddress.Locator : '';
    }

No comments:

Post a Comment