четверг, 10 августа 2017 г.

Get contact info from site address


Hi fellows!

Recently I h ave had some difficults to get contact information from Site address and I did searching at least 2 days.
I tried tu use many different approaches, some of them was to complicated, some not, but all was not working unfortunately.

But today I found working ( I guess) way.
Here's the code how to get contact information from site address (either phone, email, url and so on). For my case it was Phone:

    LogisticsEntityPostalAddressView     postalAddressView;
    LogisticsElectronicAddress                  electronicAddress;
    LogisticsLocation                                 contactLocation;

    inventLocation = inventLocation::find(ShipmentTable.InventLocationId);
    if (inventLocation)
    {
        select firstonly postalAddressView
            where   postalAddressView.Entity     == inventLocation.RecId
            &&      postalAddressView.EntityType == LogisticsLocationEntityType::Site
            &&      postalAddressView.isPrimary  == NoYes::Yes;

        if (postalAddressView)
        {
            select firstOnly electronicAddress where electronicAddress.Type == LogisticsElectronicAddressMethodType::Phone
            join contactLocation where contactLocation.ParentLocation  == postalAddressView.Location
                && contactLocation.RecId == electronicAddress.Location;

            info(strFmt("Primary contact name: %1  Primary contact phone: %2",electronicAddress.Description, electronicAddress.Locator));
        }

I tried and it worked! I improved query, because originally it has 2 selects instead of 1.

Hope it will be useful for someone!

Happy DAX-ing. :)
   


Комментариев нет:

Отправить комментарий