1 Aralık 2015 Salı

AX 2012 - Add/update Customer and Vendor accounts

Customer account:
 
    CustTable                    custTable;
    DirParty                        dirParty;
    DirPartyPostalAddressView       dirPartyPostalAddressView;
    DirPartyContactInfoView         dirPartyContactInfo;
    CustGroup                       custGroup;
    DirPartyTable                   partyTable;
    DirPartyLocation                dirLocation;
    LogisticsPostalAddress          address;
    LogisticsLocation               logisticsLocation;

    ;
    select firstOnly forUpdate custTable
        where custTable.AccountNum == custAccount;
        //-------------------- custtable --------------------------
    if (custTable.RecId == 0)
    {
        custTable.initValue();
        custTable.AccountNum           = custAccount;
        custTable.CustGroup            = custGroupId;
        custTable.VATNum               = vatNum;
        custTable.IdentificationNumber = identificationNumber;
        custTable.TaxOfficeName_TR     = taxOfficeName_TR;
        custTable.Blocked              = custBlocked;
        custTable.insert(DirPartyType::Organization, custName);
    }
    else
    {
        custTable.CustGroup            = custGroupId;
        custTable.VATNum               = vatNum;
        custTable.TaxOfficeName_TR     = taxOfficeName_TR;
        custTable.IdentificationNumber = identificationNumber;
        custTable.Blocked              = custBlocked;
        custTable.update();
        update_recordSet partyTable setting name = custName, NameAlias = nameAlias
            where partyTable.RecId == custTable.Party;
    }
    //-------------------- adres -----------------------------
        dirParty = DirParty::constructFromCommon(custTable);
        select
firstonly dirPartyPostalAddressView
            where dirPartyPostalAddressView.Party == custTable.Party &&
                  dirPartyPostalAddressView.LocationName == "Address";
        dirPartyPostalAddressView.LocationName      = "Adres";
        dirPartyPostalAddressView.City              = city;
        dirPartyPostalAddressView.State             = state;
        dirPartyPostalAddressView.Street            = street;
        dirPartyPostalAddressView.IsPrimary         = NoYes::Yes;
        dirPartyPostalAddressView.CountryRegionId   = countryRegionId;
        dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
        if (phone)
        {
            dirParty = DirParty::constructFromCommon(custTable);
            select
firstonly dirPartyContactInfo
                where dirPartyContactInfo.Party == custTable.Party &&
                      dirPartyContactInfo.LocationName == "Phone";
            dirPartyContactInfo.LocationName    ="Phone";
            dirPartyContactInfo.Locator         = phone;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
        }
        if (email)
        {
            select firstonly dirPartyContactInfo
                where dirPartyContactInfo.Party == custTable.Party &&
                      dirPartyContactInfo.LocationName == "E-mail";
            dirPartyContactInfo.LocationName    ="E-mail";
            dirPartyContactInfo.Locator         = email;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
        }


There's just one difference with vendor and customer creating is about separated creating DirParty record. If account is a person instead of organization, you have to use DirPersonName table instead of DirOrganization table:

    VendTable                    vendTable;

    DirParty                        dirParty;
    DirPartyPostalAddressView       dirPartyPostalAddressView;
    DirPartyContactInfoView         dirPartyContactInfo;
    VendGroup                       vendGroup;
    DirPartyTable                   partyTable;
    DirPartyLocation                dirLocation;
    LogisticsPostalAddress          address;
    LogisticsLocation               logisticsLocation;
    DirOrganization                 organization;

    ;

    select firstOnly forUpdate vendTable
        where vendTable.AccountNum == vendAccount;
        //-------------------- vendTable --------------------------
    if (vendTable.RecId == 0)
    {
        organization.Name                    = vendName;
        organization.NameAlias               = nameAlias;
        organization.LanguageId              = CompanyInfo::languageId();
        organization.insert();

        vendTable.initValue();
        vendTable.party                = organization.recid;
        vendTable.AccountNum           = vendAccount;
        vendTable.vendGroup            = vendGroupId;
        vendTable.VATNum               = vatNum;
        vendTable.Blocked              = VendBlocked;
        vendTable.TaxOfficeName_TR     = taxOfficeName_TR;
        vendTable.insert();
    }
    else
    {
        vendTable.vendGroup            = vendGroupId;
        vendTable.VATNum               = vatNum;
        vendTable.Blocked              = VendBlocked;
        vendTable.update();
        update_recordSet organization setting name = vendName, NameAlias = nameAlias
            where organization.RecId == vendTable.Party;
    }

2 yorum:

  1. How do you make this work to read off a csv file? so that we can update/add multiple records

    YanıtlaSil
    Yanıtlar
    1. There are lots of CVS import sample at google. You may merge this code part with one of samples.

      Sil