Thursday, 26 January 2017

Set Delivery Address on Sales order through code X++ AX 2012

In this post we will learn how to set delivery address / over rider the default customer delivery address on a Sales order.

This method will return the  LogisticsPostalAddress recId, which we will assign to parm method of AXsalesTable class..
axsalesTable.parmDeliveryPostalAddress(this.setDeliveryAddress(_tmpSalesheaders));
private RecId setDeliveryAddress(TmpSalesTable           _tmpSalesheaders)
{
    DirPartyPostalAddressView   addressView, ret;
    DirPartyRecId                        partyRecId;
    DirParty                                 dirParty;
    LogisticsPostalAddress          postalAddress;
    ;
    //Create new Name
    partyRecId = DirPartyTable::createNew(DirPartyType::None, _tmpSalesheaders.DeliveryName).RecId;
   
    addressView.CountryRegionId = _tmpSalesheaders.DeliveryCountryRegionId;//"AUS";
    addressView.State = _tmpSalesheaders.DeliveryState;//"VIC";
    addressView.ZipCode = _tmpSalesheaders.DeliveryZipCode;//"3000";
    addressView.Street  = _tmpSalesheaders.DeliveryStreet;//"238 Flinders St";
    addressView.Party = partyRecId;
   
    //Handel errors for addresses
    if (!LogisticsAddressCountryRegion::exist(addressView.CountryRegionId))
        throw error(strFmt("@SYS9347",addressView.CountryRegionId));
    if (addressView.County && !LogisticsAddressCounty::exist(addressView.CountryRegionId, addressView.State, addressView.County))
        throw error(strFmt("@SYS72719",addressView.County));
    if (addressView.State && !LogisticsAddressState::exist(addressView.CountryRegionId, addressView.State))
        throw error(strFmt("@SYS72786",addressView.State));
    if (!LogisticsAddressZipCode::exist(addressView.ZipCode))
        throw error(strFmt("@SYS24626",addressView.ZipCode));

    addressView.Party  = partyRecId;
    if( addressView.Street || addressView.ZipCode || addressView.City || addressView.State || addressView.CountryRegionId)
    {
        DirParty = DirParty::constructFromPartyRecId(addressView.Party );
        ret = DirParty.createOrUpdatePostalAddress(addressView);
        postalAddress = LogisticsPostalAddress::findByLocation(ret.Location);
    }
    return postalAddress.RecId;
}

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...