Thursday, 29 June 2017

Create New customer address and update customer address using x++ code

How to update customer address using Code
static void updateCustomerAddress(Args _args)
{
    LogisticsPostalAddress      address;
    CustTable                   custtable;
    DirPartyPostalAddressView   postaladdressView;
    DirParty                    dirparty;
    LogisticsLocation           location;
    DirPartyTable               dirPartyTable;
   
    while select custtable where custtable.AccountNum == "100"
                         join  dirPartyTable where custtable.Party ==   dirPartyTable.RecId
                         join  location where dirPartyTable.PrimaryAddressLocation == location.RecId
                         join  address  where address.Location == location.RecId
    {
        if(location.RecId)
        {
            ttsBegin;       
                location.Description = "Test";
                location.selectForUpdate(true);
                location.update();  
            ttsCommit;
        }
        if(address.RecId)
        {
            ttsBegin;       
       
            address.Street  =   "Test";
            //address.ZipCode =   //"555111";
            //address.City    = "hyderabad";
            //address.CountryRegionId = "Ind";
            address.Address = address.Street +" "+ address.ZipCode +" "+ address.City +" "+address.CountryRegionId;
            address.selectForUpdate(true);
            address.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            address.update();
            ttsCommit;
        }
        info(strFmt("Customer %1 Description %2 Address %3",custtable.AccountNum,location.Description,address.Address));
    }

}

How to create new customer address using x++ code
static void createCustomerAddress(Args _args)
{
    LogisticsPostalAddress address;  
    DirPartyPostalAddressView   addressView;
    DirParty dirParty;
    DirPartyTable   dirPartyTable;
    CustTable   custTable;
    container  roles;
   
    while select custTable
          join  dirPartyTable where custtable.Party ==   dirPartyTable.RecId
            && DirPartyTable.Name like "Test*"
    {  
        address.Street = custTable.name() +"\n"+ "Avenue";  
        address.ZipCode = "08837";  
        address.City = "Edison";  
        address.State = "NJ";
        address.CountryRegionId = "USA";
        addressView.IsPrimary = 1;
        addressView.LocationName = "USTC";
        addressView.Party = CustTable.Party;  
        addressview.initFromPostalAddress(address);  
        DirParty = DirParty::constructFromPartyRecId(CustTable.Party);  
        roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];  
        DirParty.createOrUpdatePostalAddress(addressView,roles);
        info(strFmt("Customer %1 Description %2 Address %3",custtable.AccountNum,addressView.LocationName,address.Street));
    }
         info("done");

 }

No comments:

Post a Comment