Tuesday, August 20, 2019

get the postal address in x++ Dynamics Ax

in order to get the Logistics postal address in Dynamics Ax you have different options. Here some examples.

For this example I choose to search for the postal address of an operating unit (department), but the same concept is valid for any other entity (clients, suppliers, workers…)

static void JobEF_AddressDepartment(Args _args)

{

    OMOperatingUnit department =  OMOperatingUnit::find(

                    MYD_HcmPositionDepartmentUtil::getOMDepartmentRecIdFromUnitNumber('123'),

                    OMOperatingUnitType::OMDepartment);

    DirParty dirParty = DirParty::constructFromCommon(department);

    RecId dirPartyRecId = dirParty.getPartyRecId();

 

    LogisticsLocationEntity logisticsLocationEntity = dirParty.getPrimaryPostalAddressLocation();

    LogisticsLocationRecId logisticsLocationRecId = logisticsLocationEntity.parmLocationRecId();

 

    //I have different options

 

    //1) I can instatiate the view DirPartyPostalAddressView

    DirPartyPostalAddressView dirPartyPostalAddressView = dirParty.getPostalAddress(logisticsLocationRecId);

 

    //2) I can instantiate LogisticsPostalAddress

    LogisticsPostalAddress logisticsPostalAddress = LogisticsPostalAddress::findByLocation(logisticsLocationRecId);

 

    //3) I can instantiate LogisticsPostalAddress in just one method:

    LogisticsPostalAddress logisticsPostalAddress1 = DirParty::primaryPostalAddress(dirPartyRecId);

 

    info(DirParty::getAddress(dirPartyRecId));

    info(dirPartyPostalAddressView.City);

    info(logisticsPostalAddress.City);

    info(logisticsPostalAddress1.City);

    info(dirPartyPostalAddressView.Street);

    info(logisticsPostalAddress.Street);

    info(logisticsPostalAddress1.Street);

 

    info(logisticsPostalAddress1.StreetNumber);

    info(logisticsPostalAddress1.Street);

    info(logisticsPostalAddress1.City);

    info(logisticsPostalAddress1.ZipCode);

    info(logisticsPostalAddress1.State);

    info(logisticsPostalAddress1.County);

    info(logisticsPostalAddress1.CountryRegionId);

    info(logisticsPostalAddress1.PostBox);

    info(logisticsPostalAddress1.DistrictName);

}

 

No comments:

Post a Comment