Oct 5, 2016

How to : Create vendor or customer address through X++ (X++로 벤더 또는 고객 주소 생성하기)

static void create_CustVendAddress( LogisticsLocationRoleType       _LogisticsLocationRoleType,
                                    TableId                         _TableId,
                                    AccountNum                      _AccountNum,
                                    AddressCountryRegionId          _CountryRegionId,
                                    Description                     _LocationName,
                                    str                             _City,
                                    str                             _County,
                                    str                             _Country,
                                    str                             _Street,
                                    str                             _State,
                                    str                             _ZipCode)
{
    CustTable                       _CustTable;
    VendTable                       _VendTable;
    DirPartyTable                   _DirPartyTable;
    DirParty                        _DirParty;
    DirPartyPostalAddressView       _DirPartyPostalAddressView;
    LogisticsLocation               _LogisticsLocation;
    LogisticsPostalAddress          _LogisticsPostalAddress;
    switch (tableId2name(_TableId))
    {
        case "CustTable":
            select firstOnly _CustTable
            index hint AccountIdx
            join _DirPartyTable
            where _CustTable.AccountNum == _AccountNum
            && _DirPartyTable.RecId == _CustTable.Party;
            break;
        case "VendTable":
            select firstOnly _VendTable
            index hint AccountIdx
            join _DirPartyTable
            where _VendTable.AccountNum == _AccountNum
            && _DirPartyTable.RecId == _VendTable.Party;
            break;
    }
    if (_DirPartyTable)
    {
        _LogisticsLocation = LogisticsLocation::create(_LocationName,
                            NoYes::Yes);
        DirParty::addLocation(  _DirPartyTable.RecId,
                                _LogisticsLocation.RecId,
                                true,
                                true,
                                false,
                                [LogisticsLocationRole::findBytype(_LogisticsLocationRoleType).RecId]);
        _LogisticsPostalAddress.clear();
        _LogisticsPostalAddress.initValue();
        _LogisticsPostalAddress.CountryRegionId         = _CountryRegionId;
        _LogisticsPostalAddress.City                    = _City;
        _LogisticsPostalAddress.County                  = _County;
        _LogisticsPostalAddress.Street                  = _Street;
        _LogisticsPostalAddress.State                   = _State;
        _LogisticsPostalAddress.ZipCode                 = _ZipCode;
        _LogisticsPostalAddress.Address                 = LogisticsPostalAddress::formatAddress(_Street,
                                                                                                _ZipCode,
                                                                                                _City,
                                                                                                _Country,
                                                                                                _State,
                                                                                                _County);
        _LogisticsPostalAddress.Location                = _LogisticsLocation.RecId;
        _LogisticsPostalAddress.ValidFrom               = DateTimeUtil::utcNow();
        _LogisticsPostalAddress.ValidTo                 = DateTimeUtil::maxValue();
        if (_LogisticsPostalAddress.validateWrite())
        {
            _LogisticsPostalAddress.insert();
        }
    }
}

No comments:

Post a Comment