Wednesday 31 October 2012

Unit of Work

Hi all.

Unit of Work is a new framework , which is being introduced in AX 2012.
Now let us explore what is need of having this framework  :

Suppose we do have Two tables , TableHeader and TableLine.
Now we want to insert bulk data in these two tables , TableLine is linked with TableHeader by RecID.

So first we need to insert the data in TableHeader and then pass the recid of this table to Tableline and insert the record. So there are 2 major issue is : We need to hold recId of Parent table and pass to Tableline and we have to hit database with each insert.

Now Unit of Work framework come into picture and helps us , we dont have to hold the recid of parent table and also we can insert all data in a single trip . How ... Let us Implement this :

1.Create 2 table SKU_Table and SKU_Line.
2.SKU_Line is related to SKU_Table by RecId.
3.Go to relation of table and make sure property CreateNavigationPropertyMethods = true
by making this property true , system will add appropriate methods to table SKU_Line
4 . Now we are ready to go


public void Insert()
{
    SKU_Table                       SKU_Table;
    SKU_Line                        SKU_Line;      
    UnitofWork                      UnitofWork;
 
    UnitofWork                      =  new UnitofWork();
    while select aaaaa
    {
     //insert data in parent table
        SKU_Table.clear();   
        SKU_Table.somefield                 = cccc;      
        UnitofWork.insertonSaveChanges(SKU_Table);
   
        while select bbbb
        {
               //insert data in child table
            SKU_Line.clear();
            SKU_Line.somefield                 = ddddd;
            SKU_Line.SKU_Table(SKU_Table);
            UnitofWork.insertonSaveChanges(SKU_Line);
        }      
    }
//Now insert data in a single trip
    UnitofWork.saveChanges();
}

Thursday 18 October 2012

Create Product Variant using X++


How to create a product variant with Dimensions provided  

ecoResDistinctProductVariant        ecoResDistinctProductVariant;
    EcoResProductVariantDimensionValue  EcoResProductVariantDimensionValue;
    RefRecId                                   ecoResDistinctProductVariantRecId;
    EcoResProductReleaseManagerBase     releaseManager;
    container productDimensions;


//Create a container to hold dimension values
productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer(ConfigurationName,
                                                                                        Size,
                                                                                        ColorId,
                                                                                        InventStyleId);
//Create Product search name

ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
                                                                   EcoResProduct::find(InventTable.Product).productNumber(),
                                                                    productDimensions);

//Create Product variant with Product and dimensions provided

    ecoResDistinctProductVariantRecId = EcoResProductVariantManager::createProductVariant(InventTable.Product,ecoResDistinctProductVariant.DisplayProductNumber,productDimensions);

//Find newly created Product Variant
    ecoResDistinctProductVariant = ecoResDistinctProductVariant::find(ecoResDistinctProductVariantRecId);
//Now release the Product variant
    releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
    releaseManager.release();



Hope this will help u guys :)



Wednesday 10 October 2012

create Product master by using X++ , AX 2012

Following code to create Product master by using X++
static void ProductCreate(Args _args)
{

EcoResProductService erProdSvc;
EcoResEcoResProduct EcoResProd;
EcoResEcoResProduct_Product_Master ProdMast;
EcoResEcoResProduct_Translation Translation;
EcoResEcoResProduct_Identifier Identifier;
EcoResEcoResProduct_ProductDimGroup ProdDimGroup;

//Initialize the service object
erProdSvc = EcoResProductService::construct();
EcoResProd = new EcoResEcoResProduct();
ProdMast = new EcoResEcoResProduct_Product_Master();

//ProdDimGroup = new EcoResEcoResProduct_ProductDimGroup();
//Newly created and initialize prodMast
ProdMast.parmDisplayProductNumber("IDB-PM002");
ProdMast.parmProductType(EcoResProductType::Item);
ProdMast.parmSearchName("IDB Product Master 1");


//Create a new translation object:
Translation = ProdMast.createTranslation().addNew();

Translation.parmDescription("IDB product Master");
Translation.parmLanguageId("en-us");
Translation.parmName("IDB Product Master 1");
Identifier = ProdMast.createIdentifier().addNew();

Identifier.parmProductNumber("IDB-PM002");
ProdDimGroup = ProdMast.createProductDimGroup().addNew();
ProdDimGroup.parmProduct("IDB-PM001");
ProdDimGroup.parmProductDimensionGroup("Col");


ProdMast.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::PredefinedVariants);
EcoResProd.createProduct().add(ProdMast);

erProdSvc.create(EcoResProd);

Lookup for RealEdit Control in Ax2012

Lookup for RealEdit Control in Ax2012

we cant build the lookup for RealEdit control by using SysLookup functionality for that we have to customize the SysTableLookup class method performFormLookup()
Add the case for switch for handling the FormRealControl.
FormRealControl     callingRealControl;


 case classNum(FormRealControl):
            callingRealControl = callingControl;
            callingRealControl.performFormLookup(this.formRun());
            break;