Warm tip: This article is reproduced from stackoverflow.com, please click
axapta microsoft-dynamics x++

How to get Address using inventsiteid x++

发布于 2020-05-12 13:24:07

Like in thread tittle. How or by what can I get LocationAddress info having inventsiteid ?? There are so many tables and views im confused. I need to pick site address for current siteid.

Questioner
Radosław Mierzejewski
Viewed
29
Alex Kwitny 2020-02-28 00:19

Create this job and replace the inventSiteId with your site.

static void Job107(Args _args)
{
    InventSiteId                        inventSiteId    = 'MySite'; // PUT YOUR SITE HERE
    InventSite                          inventSite      = InventSite::find(inventSiteId);
    InventSiteLogisticsLocation         siteLocation;
    InventSiteLogisticsLocationRole     siteLocationRole;
    LogisticsLocationRole               locationRole;
    LogisticsPostalAddress              logisticsPostalAddress;

    // Method 1 - List all addresses. Refine query as needed.
    while select logisticsPostalAddress
    join siteLocation
        order by IsPrimary desc
        where logisticsPostalAddress.Location           == siteLocation.Location    &&
              siteLocation.Site                         == inventSite.RecId
    join siteLocationRole
        where siteLocationRole.SiteLogisticsLocation    == siteLocation.RecId
    join locationRole
        where locationRole.RecId                        == siteLocationRole.LocationRole
    {
        info(strFmt("Role: %1; Address: %2", locationRole.Type, logisticsPostalAddress.Address));
    }

    // Method 2; 1-liner for single address, good for just getting primary. Change role type for different addresses
    info(LogisticsPostalAddress::findByLocation(InventSite::getLocationFromRole(InventSite::find(inventSiteId).RecId, LogisticsLocationRoleType::Delivery)).Address);
}