update etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
update etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

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;
    }

30 Kasım 2015 Pazartesi

AX 2012 - Add/update product

//http://daxtechies.blogspot.com.tr/2013/12/ax2012-r2-creating-product-or-product.html
if ( InventTable::find(itemId).ItemId != "" )
            this.updateProduct();
        else
            this.newProduct();
        itemRecId = EcoResProduct::findByDisplayProductNumber(itemId).RecId;
        this.updateInventTable();


private void newProduct(EcoResProductSubtype _subType = EcoResProductSubtype::Product)
{
    EcoResProductService                    erProdSvc;
    EcoResEcoResProduct                     ecoResProd;
    EcoResEcoResProduct_Product_Master      prodMaster;
    EcoResEcoResProduct_Translation         translation;
    EcoResEcoResProduct_Identifier          identifier;
    EcoResEcoResProduct_ProductDimGroup     prodDimGroup;
    EcoResEcoResProduct_Product_Distinct    distMaster;
    EcoResEcoResProduct_StorageDimGroup     storDimGroup;
    EcoResEcoResProduct_TrackingDimGroup    tracDimGroup;
    InventTable                             inventTable;

    erProdSvc   = EcoResProductService::construct();
    ecoResProd  = new EcoResEcoResProduct();

    if (_subType == EcoResProductSubtype::ProductMaster) //varianted product
    {
        prodMaster    = new EcoResEcoResProduct_Product_Master();
        prodMaster.parmDisplayProductNumber(itemId);
        prodMaster.parmProductType(EcoResProductType::Item);
        prodMaster.parmSearchName(nameAlias);
        prodMaster.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::PredefinedVariants);

        translation = prodMaster.createTranslation().addNew();
        identifier  = prodMaster.createIdentifier().addNew();

        prodDimGroup = prodMaster.createProductDimGroup().addNew();
        prodDimGroup.parmProduct(itemId);
        prodDimGroup.parmProductDimensionGroup(dimGroup);

        storDimGroup = prodMaster.createStorageDimGroup().addNew();

        tracDimGroup = prodMaster.createTrackingDimGroup().addNew();
    }
    if (_subType == EcoResProductSubtype::Product) //product
    {
        distMaster = new EcoResEcoResProduct_Product_Distinct();
        distMaster.parmDisplayProductNumber(itemId);
        distMaster.parmProductType(EcoResProductType::Item);
        distMaster.parmSearchName(nameAlias);

        translation = distMaster.createTranslation().addNew();
        identifier  = distMaster.createIdentifier().addNew();

        storDimGroup = distMaster.createStorageDimGroup().addNew();

        tracDimGroup = distMaster.createTrackingDimGroup().addNew();
    }

    translation.parmDescription(itemName);
    translation.parmLanguageId(SystemParameters::getSystemLanguageId());
    translation.parmName(itemName);

    storDimGroup.parmProduct(itemId);
    storDimGroup.parmStorageDimensionGroup(storeGroup);

    tracDimGroup.parmProduct(itemId);
    tracDimGroup.parmTrackingDimensionGroup(trackingGroup);

    identifier.parmProductNumber(itemId);
    if (_subType == EcoResProductSubtype::ProductMaster) //varianted product

        ecoResProd.createProduct().add(prodMaster);
    if (_subType == EcoResProductSubtype::Product) //product
        ecoResProd.createProduct().add(distMaster);

    erProdSvc.create(ecoResProd);
    EcoResProductReleaseManagerBase::releaseProduct(EcoResProduct::findByProductNumber(itemId).RecId,CompanyInfo::find().RecId);

}


private void updateProduct()
{
    InventTableModule           inventModule;
    EcoResProductTranslation    translation;

    update_recordSet inventModule setting unitId = unitId
        where inventModule.ItemId == itemId;
    update_recordSet translation
        setting Description = itemName,
                Name        = itemName
        where translation.Product == itemRecId &&
              translation.LanguageId == SystemParameters::getSystemLanguageId();
}

private void updateInventTable()
{
    InventTable             inventTable;
    InventModelGroupItem    modelGroup;
    update_recordSet inventTable
        setting NetWeight   = netWeight,
                TaraWeight  = taraWeight,
                GrossDepth  = depth,
                GrossWidth  = width,
                GrossHeight = height,
                UnitVolume  = volume
        where
            inventTable.Product == itemRecId;
    if (inventModelGroupId == "")
        delete_from modelGroup
            where modelGroup.ItemId == itemId && modelGroup.ItemDataAreaId == curext() &&
                  modelGroup.ModelGroupDataAreaId == curext();
    else
    {
        select firstOnly forUpdate modelGroup
            where modelGroup.ItemId == itemId && modelGroup.ItemDataAreaId == curext() &&
                  modelGroup.ModelGroupDataAreaId == curext();
        modelGroup.ItemId = itemId;
        modelGroup.ItemDataAreaId = curext();
        modelGroup.ModelGroupDataAreaId = curext();
        modelGroup.ModelGroupId = inventModelGroupId;
        if (modelGroup.RecId == 0)
            modelGroup.insert();
        else
            modelGroup.update();
    }
}

17 Temmuz 2014 Perşembe

AX 2012 - My New Field's Value Disappearing when Editing VendInvoiceInfoTable

I add a new field to VendInvoiceInfoTable When try to edit with VendEditInvoice form I saw my new field's value is empty. After a long research I found out Axapta copy source record to another record and edit this new record. Meanwhile Axapta skips my new field. Axapta uses table method copyFromHeader while copying. Add my new line:

    this.VendorRequestedWorkerEmail = _header.VendorRequestedWorkerEmail;
    //my new field
    this.myNewField     = _header.
myNewField;

Problem overed. Same method valid for related VendInvoiceInfoLine table too.