Sirus
Sirus

Reputation: 502

how to find shortname of country from custtable

I need to query the short name of the country name based on custtable.

I know the information lies in

LogisticsAddressCountryRegionTranslation.shortname;
 LogisticsAddressCountryRegion.countryregionid;

Problem is, going through the relations i don't see a way to link back to custtable. There used to be a countryregionid in the custtable that would link back but it is changed to DEL_countryregionid and cannot use this anymore. How can i obtain this information. Using ax 2012

Upvotes: 1

Views: 1585

Answers (1)

Alex Kwitny
Alex Kwitny

Reputation: 11564

An important thing to note is a Customer record can have multiple addresses. So this answer uses the Primary Postal Address. This may not be your use case.

Also the "ShortName" is region specific.

static void Job20(Args _args)
{
    CustTable                                   custTable;
    LogisticsAddressCountryRegionTranslation    countryRegionTranslation;
    UserInfo                                    userInfo;
    LogisticsAddressCountryRegion               countryRegion;
    LogisticsPostalAddress                      postalAddress;

    select firstOnly custTable;

    postalAddress = custTable.postalAddress();

    countryRegion   = LogisticsAddressCountryRegion::find(postalAddress.CountryRegionId);

    select firstonly Language from userInfo where userInfo.Id == curUserId()
        join countryRegionTranslation
            where countryRegionTranslation.CountryRegionId == countryRegion.CountryRegionId &&
                    countryRegionTranslation.LanguageId      == userInfo.Language;

    info(strFmt("Address: %1; ShortName: %2", postalAddress.Address, countryRegionTranslation.ShortName));
}

Upvotes: 2

Related Questions