Monday, September 30, 2013

Updating ProductCategoryHierarchy for an item using X++ Programming

static void UpdatingProductCategoryHierarchy(Args _args)
{

EcoResProduct _EcoResProduct;

EcoResProductCategory _EcoResProductCategory;

EcoResCategoryHierarchy EcoResCategoryHierarchy;

;

select forUpdate _EcoResProduct
where _EcoResProduct.DisplayProductNumber == "itemid";   // Item Number

select forUpdate _EcoResProductCategory
where _EcoResProductCategory.Product == EcoResProduct::findByDisplayProductNumber(_EcoResProduct.DisplayProductNumber).RecId;

if(_EcoResProductCategory)
{

ttsBegin;
_EcoResProductCategory.Product = EcoResProduct::findByDisplayProductNumber(_EcoResProduct.DisplayProductNumber).RecId;

   //Category Hierarchy Name

EcoResCategoryHierarchy = EcoResCategoryHierarchy::findByName(
"HierarchyName");
_EcoResProductCategory.CategoryHierarchy = EcoResCategoryHierarchy.RecId;

    //Category Name
  _EcoResProductCategory.Category = EcoResCategory::findByName('category',EcoResCategoryHierarchy.RecId).RecId;
   _EcoResProductCategory.update();

ttsCommit;
}

if(!_EcoResProductCategory)
{

ttsBegin;
_EcoResProductCategory.Product = EcoResProduct::findByDisplayProductNumber(_EcoResProduct.DisplayProductNumber).RecId;

EcoResCategoryHierarchy = EcoResCategoryHierarchy::findByName(
"HierarchyName");//Category Hierarchy Name


_EcoResProductCategory.CategoryHierarchy = EcoResCategoryHierarchy.RecId;

// Category Nam
_EcoResProductCategory.Category = EcoResCategory::findByName(
'category',EcoResCategoryHierarchy.RecId).RecId; e
_EcoResProductCategory.insert();

ttsCommit;
}
}


No comments:

Post a Comment