0

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.

Tweene
  • 257
  • 4
  • 16

2 Answers2

1

It can be a bit confusing. This is a great article for you to do this.

Get address from inventsiteid

Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
  • I did see this article already. Did not really help me here. My inventsitelogisticslocation is almost empty. I should get is probably somewhere from dirparty but idk... – Tweene Feb 27 '20 at 13:08
  • Tell me the tables or tables you have to start the search. – Jonathan Bravetti Feb 27 '20 at 14:45
  • DirPartyTable, LogisticsPostalAdress. I looked some Views of Address and DirPartys there is the data I need but I get problems to join it to my siteid. There is like EntityView of postaladress that should work with Entity == inventsite.recid but most addresses are not connected by that... – Tweene Feb 29 '20 at 08:48
1

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);
}
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Tried both methods but info didnt give me anything here. BTW I need to get a int64 adresslocation since I need to put it into a field of PurchCreateOrder. – Tweene Feb 29 '20 at 08:41
  • Did you replace the text `MySite` with your site? This code works...you need to provide more information when you just say "It doesn't work". Does your `inventSite` variable above contain a value? `SiteLocation.Location` is the location recid. The data is all there. Debug your code. – Alex Kwitny Feb 29 '20 at 15:54
  • By bad. Didnt explained it well. It works but.. in my sitelocation are only 2 locations pasted. So this code works for 2 of 20 addresses. I should get it somewhere from DIrPartyTables I think. They are somehow connected to siteid but I cant find where. – Tweene Mar 02 '20 at 09:33
  • The value I need must be int64 to put it into a form field – Tweene Mar 02 '20 at 11:38
  • 2
    Edit your question or ask a new question, this answer solves exactly what you're asking. Your question is just a title of a post, plus you repeat the same question in the body. Please see [Asking a good question](https://stackoverflow.com/help/how-to-ask). Try to understand from the perspective of someone answering this. I provide two correct solutions to the problem, then you basically say "it doesn't work", then you ask a new question in the comment. And this has happened on multiple questions now. It makes me question the time spent answering. – Alex Kwitny Mar 02 '20 at 15:49