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

9 Ağustos 2017 Çarşamba

AX 2012 - Add filter for one dimension for a query's financial dimension

If you try to this with add tables you'll see you have to add lots of table to query. There is a class which do this for you DimensionProvider with AX 2012:

DimensionProvider           dimProvider = new DimensionProvider();


        dimProvider.addAttributeRangeToQuery(element.query(),element.query().dataSourceNo(1).name(),
       FieldStr(MyTable,DefaultDimension),
        DimensionComponent::DimensionAttribute,
        OMOperatingUnit::find(depRecId,OMOperatingUnitType::OMDepartment).OMOperatingUnitNumber,
            "Department",true);

BTW if you get an error like Unknown type: RefRecId it would be about EDT of your table. In my case they used RefRecId EDT instead of DimensionDefault EDT with DefaultDimension field. In your case it would be other than RefRecId. There is a bug like this with original AX table HcmEmployment.

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

20 Temmuz 2015 Pazartesi

AXAPTA - Remove or add invent reservation

You can add or remove reservation with this code which I learned from Volkan Şişman:

  
InventUpd_Reservation       invUpdReservation; 
... 
//remove 
invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,200,false);
            invUpdReservation.updateNow();

...
//add
          invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,400,false);
            invUpdReservation.updateNow();


Or:

//add
     InventUpd_Reservation::updateReserveBuffer(journalTrans, journalTrans.Qty);

//remove
     InventUpd_Reservation::updateReserveBuffer(journalTrans, abs(journalTrans.Qty)); 

Or:

//add

InventUpd_Reservation::newInventDim(InventTrans.inventMovement(true),InventTrans.inventDim(),-InventTrans.qty,true).updateNow();

10 Eylül 2014 Çarşamba

AX 2012 - Add a new dimension value to Default dimension

I wrote this code from one of Eyüp Tezar's code:

DimensionDefault DefDim;
DimensionAttribute                  dimensionAttribute;
DimensionAttributeValue             newValue;
DimensionAttributeValueSetStorage   dimensionStorage;


DefDim = mytable.Defaultdimension;

dimensionAttribute = DimensionAttribute::find(myDimRecid);


newValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,
        myDimValue,false,true);

dimensionStorage = DimensionAttributeValueSetStorage::find(DefDim);
dimensionStorage.addItem(newValue);

DefDim = dimensionStorage.save();

//------------------- another dimension ------------------------

dimensionAttribute = DimensionAttribute::findbyName("Project");


newValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,
        myDimValue2,false,true);

dimensionStorage = DimensionAttributeValueSetStorage::find(DefDim);
dimensionStorage.addItem(newValue);

DefDim = dimensionStorage.save();