Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Need to select activat...
Finance forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Need to select activate ineffective Address (LogisticsPostalAddress) record through code

Posted on by 47
I am having issues processing shipment waves that have a Sales Order on it with an ineffective date. We have a integration that runs a customer address sync that seems to be deactivated addresses all the time, leaving many open sales orders with now ineffective addresses. I am trying to get the client to get rid of the sync altogether at this point.
In the meantime, I want to add a fix to select the ineffective address on the customer and make it active during the /processing/ of the wave. The client does not need the effective/ineffective address funtionality at all in D365. If you know how to turn LogisticsPostalAddress table into not a ValidTimeState table that would be good too. 
I have code below but does not seem to be working. This code gets hit when processing a wave with shipment lines.
[ExtensionOf(classStr(WhsPostEngine))]final class WhsPostEngine_RevolutionDancewear_Extension{    public static boolean post(WHSWaveTable _waveTable, WHSReleaseToWarehouseId _releaseToWarehouseId)    {        WHSWaveLine waveLine;        SalesTable salesTable;        LogisticsPostalAddress LogisticsPostalAddress;        LogisticsPostalAddress logisticsPostalAddressOld;        utcdatetime now = DateTimeUtil::getSystemDateTime();        utcdatetime futureDate = DateTimeUtil::addMonths(now,6);        DirPartyTable dirPartyTable;        CustTable     custTable;        utcDateTime                     utcMinVal = DateTimeUtil::minValue();        utcDateTime                     utcMaxVal = DateTimeUtil::maxValue();        Common      common;        DictTable   dictTable;        ;         ttsbegin;        while select waveLine where waveLine.WaveID == _waveTable.waveID            outer join SalesTable where SalesTable.SalesID == waveLine.OrderNum          //  outer join forupdate validtimeState(dateFrom,dateTo) * from LogisticsPostalAddress where LogisticsPostalAddress.RecId == SalesTable.AddressRefRecId        {            dictTable = new DictTable(salesTable.AddressRefTableId);            common = dictTable.makeRecord();             //common.selectForUpdate(_forUpdate);             select custTable where custTable.RecId == salesTable.AddressRefRecId;            LogisticsPostalAddress = CustTable.postalAddress();            //select dirPartyTable where dirPartyTable.RecId == custTable.Party;            while select forupdate validtimeState(utcMinVal,utcMaxVal) logisticsPostalAddressOld where logisticsPostalAddressOld.Location == LogisticsPostalAddress.Location                && logisticsPostalAddressOld.RecId != LogisticsPostalAddress.RecId            //logisticsPostalAddress where logisticsPostalAddress.RecId == SalesTable.AddressRefRecId;            if(LogisticsPostalAddress.ValidTo < now)            {                logisticsPostalAddressOld.validTimeStateUpdateMode(ValidTimeStateUpdate::CreateNewTimePeriod);                logisticsPostalAddressOld.ValidTo = futureDate;                logisticsPostalAddressOld.update();            }        }        ttscommit;        boolean ret = next post(_waveTable, _releaseToWarehouseId);        return ret;    }}
Please excuse the bad paste in the insert code snippet, I am not sure why its reformatting it
Here is code again below
 
[ExtensionOf(classStr(WhsPostEngine))]
final class WhsPostEngine_RevolutionDancewear_Extension
{
    public static boolean post(WHSWaveTable _waveTable, WHSReleaseToWarehouseId _releaseToWarehouseId)
    {
        WHSWaveLine waveLine;
        SalesTable salesTable;
        LogisticsPostalAddress LogisticsPostalAddress;
        LogisticsPostalAddress logisticsPostalAddressOld;
        utcdatetime now = DateTimeUtil::getSystemDateTime();
        utcdatetime futureDate = DateTimeUtil::addMonths(now,6);
        DirPartyTable dirPartyTable;
        CustTable     custTable;
        utcDateTime                     utcMinVal = DateTimeUtil::minValue();
        utcDateTime                     utcMaxVal = DateTimeUtil::maxValue();
        Common      common;
        DictTable   dictTable;
        ;
 
        ttsbegin;
        while select waveLine where waveLine.WaveID == _waveTable.waveID
            outer join SalesTable where SalesTable.SalesID == waveLine.OrderNum
          //  outer join forupdate validtimeState(dateFrom,dateTo) * from LogisticsPostalAddress where LogisticsPostalAddress.RecId == SalesTable.AddressRefRecId
        {
            dictTable = new DictTable(salesTable.AddressRefTableId);
            common = dictTable.makeRecord();
 
            //common.selectForUpdate(_forUpdate);
 
            select custTable where custTable.RecId == salesTable.AddressRefRecId;
            LogisticsPostalAddress = CustTable.postalAddress();
            //select dirPartyTable where dirPartyTable.RecId == custTable.Party;
            while select forupdate validtimeState(utcMinVal,utcMaxVal) logisticsPostalAddressOld where logisticsPostalAddressOld.Location == LogisticsPostalAddress.Location
                && logisticsPostalAddressOld.RecId != LogisticsPostalAddress.RecId
            //logisticsPostalAddress where logisticsPostalAddress.RecId == SalesTable.AddressRefRecId;
            if(LogisticsPostalAddress.ValidTo < now)
            {
                logisticsPostalAddressOld.validTimeStateUpdateMode(ValidTimeStateUpdate::CreateNewTimePeriod);
                logisticsPostalAddressOld.ValidTo = futureDate;
                logisticsPostalAddressOld.update();
            }
        }
        ttscommit;
        boolean ret = next post(_waveTable, _releaseToWarehouseId);
        return ret;
    }
}

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans