Wednesday, July 19, 2017

X++ Code To Update Customer Details In Ax 2012

X++ Code to Update R3 data for Existing Customers..


static void CustomerUpdate(Args _args)
{


CustTable                                 custTable;
DirParty                                   dirParty;
DirPartyRecId                          partyRecId;
LogisticsPostalAddress            address;
DirPartyPostalAddressView    addressView;
DirPartyTable                          dirPartyTable;
LogisticsPostalAddress           logisticsPostalAddress;
LogisticsElectronicAddress    logisticsElectronicAddress;
DirPartyPostalAddressView   dirPartyPostalAddressView;
DirPartyContactInfoView       dirPartyContactInfo;


Name                     name                  = "Test";
AccountNum         accountNum      = "DE-001";
CustGroupId          custGroupId      = "20";
CurrencyCode       currencyCode    = "INR";
PaymTermId          paymTermId     = "Net45";
DlvModeId            dlvModeId        = "30";
str                          country              = "India";
str                          State                  = "TamilNadu";
str                          city                    = "madurai";
str                          ZipCode            = "625007";
str                         street                  = "K.pudur";
str                         phone                 = "8220308543";
str                         Fax                     = "123";
str                         Email                 = "j.jackrider@gmail.com";
 
ttsBegin;
select forUpdate custTable where custtable.AccountNum == accountNum ;

if(custTable)
{

    if(name)
    {
    partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
    custTable.Party      = partyRecId;
    }

    if(custGroupId)
    {
    custTable.CustGroup = custGroupId;
    }

    if(currencyCode)
    {
    custTable.Currency = currencyCode;
    }

    if(paymTermId)
    {
    custTable.PaymTermId = paymTermId;
    }

    if(dlvModeId)
    {
    custTable.DlvMode = dlvModeId;
    }

    if(country)
    {
        partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
        custTable.Party      = partyRecId;

        DirParty = DirParty::constructFromPartyRecId(partyRecId );
        address.clear();

        address.CountryRegionId = strLRTrim(country);
        dirParty = DirParty::constructFromCommon(custTable);

        if( address.CountryRegionId != "")
        {
        address.State   = State;
        address.City    = City;
        address.ZipCode = ZipCode;
        address.Street  = Street;
        addressView.LocationName = "Address";
        addressView.IsPrimary = NoYes::Yes;
        addressView.Party = partyRecId;
        addressview.initFromPostalAddress(address);

        DirParty = DirParty::constructFromPartyRecId(addressView.Party );
        DirParty.createOrUpdatePostalAddress(addressView);
        }

    }

    if(phone)
    {
    dirPartyContactInfo.LocationName = "Phone Number";
    dirPartyContactInfo.Locator      = strLRTrim(phone);
    dirPartyContactInfo.Type         = LogisticsElectronicAddressMethodType::Phone;
    dirPartyContactInfo.Party        = partyRecId;
    dirPartyContactInfo.IsPrimary    = NoYes::Yes;
    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
    }

    if(Fax)
    {
    dirPartyContactInfo.LocationName = "Fax Number";
    dirPartyContactInfo.Locator      = strLRTrim(Fax);
    dirPartyContactInfo.Type         = LogisticsElectronicAddressMethodType::Fax;
    dirPartyContactInfo.Party        = partyRecId;
    dirPartyContactInfo.IsPrimary    = NoYes::Yes;
    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
    }

    if(Email)
    {
    dirPartyContactInfo.LocationName = "Email";
    dirPartyContactInfo.Locator      = strLRTrim(Email);
    dirPartyContactInfo.Type         = LogisticsElectronicAddressMethodType::Email;
    dirPartyContactInfo.Party        = partyRecId;
    dirPartyContactInfo.IsPrimary    = NoYes::Yes;
    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
    }

    custTable.update();
    info("Customer Updated");
}

ttsCommit;


}

No comments:

Post a Comment