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

16 Kasım 2015 Pazartesi

AXAPT - Change company with code

It's easy to change company with code. But there are two small points to care; if select/SQL used, buffer table name should be make null at every reuse. IF query used query should be create again in every loop. Query.reset() doesn't work for clear query:


Query:

 changeCompany(dataArea.Id)
{
            qRun = new QueryRun(q);
            while (qRun.next())
            {
                    custTable = qRun.get(tablenum(CustTable));
...

}
}


Select/SQL:

        changeCompany(dataArea.Id)
        {
            custTable = null;
            subSegmentGroup = null;
            while select AccountNum from custTable

...


13 Kasım 2015 Cuma

AXAPTA - Security check with X++ code

Sometimes we need security check with code (Display method etc...):



    SecurityKeySet securityKeys = new SecurityKeySet();
    ;
    securityKeys.loadUserRights(curuserid());

   if (securityKeys.access(securitykeynum("KRC_CrossCompany")) ==  AccessType::NoAccess)
   chkCrsCompany.value(NoYes::No);

12 Kasım 2015 Perşembe

AXAPTA - Add extra action to info function with SysInfoAction class

There're two ways to call a form with this class:

info(strfmt("Sales order created: %1",salesTable.SalesId),"",
            SysInfoAction_TableField::newBuffer(salesTable));


Difference with this way with up is while this way sends record data to form, upper way doesn't:

SysInfoAction_FormRun    infoAction = SysInfoAction_FormRun::newFormName(formStr(SalesTable));
;
infoAction.parmCallerBuffer(salestable);
 

info(strfmt("Satış siparişi oluşturuldu: %1",salesTable.SalesId),"",
            infoaction);