Monday, September 30, 2013

Employee Master import from CSV using X++ programming

public class EmployeeMasterImport extends RunBase
{
    CommaIo                     csvFile;
    Filename                    filename;
    DialogField                 dialogFilename;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro
    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro
    #File
}
public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    return dialog;
}

public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    return true;
}
void run()
{
    boolean                                 ret = true;
    CompanyInfo                             companyInfo;
    HcmEmploymentRecId                      newEmploymentRecId;
    ValidFromDateTime                       employmentStartDateTime;
    ValidToDateTime                         employmentEndDateTime;
    HcmWorker                               newHcmWorker;
    DirPerson                               dirPerson;
    DirPersonName                           dirPersonName;
    HcmEmploymentType                       hcmEmploymentType = HcmEmploymentType::Employee;
    NumberSeq                               numberSeqPersonnelNum;
    HcmPersonPrivateDetails                 HcmPersonPrivateDetails;
    axHcmWorkerTitle                        axHcmWorkerTitle;
    AxLogisticsPostalAddress                axLogisticsPostalAddress = new AxLogisticsPostalAddress();
    AxLogisticsLocation                     axLogisticsLocation;
    LogisticsAddressStateID                 stateId,countryid;
    DirParty Dirparty;
    DirPartyContactInfoView                 contactView;
    container                               readCon;
    counter                                 icount,inserted;
    str                                     birthdate,StartDate,firstname,middlename,lastname,EmplName,gender,city,street,mailid;
    TransDate                               StDate;
    ;
    csvFile = new CommaIO(filename, 'r');
    try
    {
        if (csvFile)
        {
            ttsbegin;
            while (csvFile.status() == IO_Status::OK)
            {
                    readCon = csvFile.read();
                    icount++;
                if (readCon  )//dont insert first record of file : header
                {
                    companyInfo = companyInfo::find();
                    EmplName = conpeek(readcon, 1);
                    firstname = conpeek(readcon, 3);
                    middlename = conpeek(readcon, 4);
                    lastname =conpeek(readcon, 5);
                    birthdate = conpeek(readcon, 6);
                    Gender = conpeek(readcon, 7);
                    stateId = conPeek(readcon,9);
                    city  = conPeek(readcon,10);
                    Street  = conPeek(readcon,11);
                    countryid = conpeek(readcon, 12);
                    StartDate = conpeek(readcon, 13);
                    mailid = conpeek(readcon, 14);
                    //employmentStartDateTime = datetobeginUtcDateTime(HrmImportEmployeeMasterdata::convDate(StartDate), DateTimeUtil::getUserPreferredTimeZone());
                    //employmentEndDateTime   = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::maxValue(), DateTimeUtil::getUserPreferredTimeZone());
                    dirPersonName.FirstName     = firstname;
                    dirPersonName.MiddleName    = middlename;
                    dirPersonName.LastName      = lastname;
                    newHcmWorker = HcmWorker::find(HcmWorkerTransition::newCreateHcmWorker(dirPersonName
                                                                                           , EmplName
                                                                                           , companyInfo.RecId
                                                                                           , hcmEmploymentType
                                                                                           , employmentStartDateTime
                                                                                           , employmentEndDateTime));
                    if (newHcmWorker.RecId == 0)
                    {
                        ret = false;
                    }
                    if (newHcmWorker.RecId == 0)
                    {
                        // Updating an existing worker
                        // If there is no active employment for the worker
                        newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
                                hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
                        if (newEmploymentRecId == 0)
                        {
                            ret = false;
                        }
                    }
                    if (ret)
                    {
                        if(numberSeqPersonnelNum)
                        {
                            // mark number sequence based ID consumed
                            numberSeqPersonnelNum.used();
                        }
                    }
                    else
                    {
                        if(numberSeqPersonnelNum)
                        {
                            numberSeqPersonnelNum.abort();
                        }
                        dirPerson.clear();
                        dirPersonName.Person = 0;
                    }
                    hcmPersonPrivateDetails.initValue();
                    hcmPersonPrivateDetails.Person      = dirPersonName.Person;
                    hcmPersonPrivateDetails.BirthDate   = HrmImportEmployeeMasterdata::convDate(birthdate);
                    hcmPersonPrivateDetails.Gender      = HrmImportEmployeeMasterdata::convGender(gender);
                    hcmPersonPrivateDetails.insert();
                    dirPerson                   = dirPerson::find(dirPersonName.Person, true);
                    DirParty = DirParty::constructFromPartyRecId(dirPerson.recid);
                    contactView.LocationName = "Delivery email";
                    contactView.Locator      = strLRTrim(mailid);
                    contactView.Type         = LogisticsElectronicAddressMethodType::Email;
                    contactView.Party        = dirPerson.recid; //partyRecId;
                    contactView.IsPrimary    = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                    //dirPerson.Initials          = conpeek(readcon, #Initials);
                   // dirPerson.ProfessionalTitle = conpeek(readcon, 8);
                   // dirPerson.update();
                    /*if(stateId)
                    {
                        stateId = subStr(stateId,1,10);
                    }*/
                    //Create address
                    axLogisticsLocation = new AxLogisticsLocation();
                    axLogisticsLocation.validateInput(true);
                    axLogisticsLocation.parmIsPostalAddress(NoYes::Yes);
                    axLogisticsLocation.parmDescription(HrmImportEmployeeMasterdata::createDescription(dirPersonName));
                    axLogisticsLocation.save();
                    axLogisticsPostalAddress    = new AxLogisticsPostalAddress();
                    axLogisticsPostalAddress.parmLocation(axLogisticsLocation.parmRecId());
                    axLogisticsPostalAddress.validateInput(true);
                    axLogisticsPostalAddress.parmCountryRegionId(countryid) ; //HrmImportEmployeeMasterdata::defaultCountryRegionId());
                    axLogisticsPostalAddress.parmState(stateId);
                    //axLogisticsPostalAddress.parmZipCode(conpeek(readcon, #PostalCode));
                    //axLogisticsPostalAddress.parmZipCodeRecId(LogisticsAddressZipCode::find(conpeek(readcon, #PostalCode)).RecId);
                    axLogisticsPostalAddress.parmStreet(street);
                    axLogisticsPostalAddress.parmCity(city);   //LogisticsAddressZipCode::find(conpeek(readcon, #PostalCode)).City);
                   // axLogisticsPostalAddress.parmCityRecId(LogisticsAddressZipCode::find(conpeek(readcon, #PostalCode)).CityRecId);
                    axLogisticsPostalAddress.save();
                    DirParty::addLocation(dirPersonName.Person, axLogisticsLocation.parmRecId(), true, true, true);
                }
            }
            ttsCommit;
        }
        icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
}

static void main(Args  args)
{
    EmployeeMasterImport        EmployeeMasterImport;
    ;
    EmployeeMasterImport =  new EmployeeMasterImport();
    if(EmployeeMasterImport.prompt())
    {
        EmployeeMasterImport.run();
    }
}

class HrmImportEmployeeMasterdata
{
    container _c1;
}

public static date convDate(str _date)
{
    Date ret;
    ;

    ret = str2Date(_date, 213);

    return ret;
}

public Static HcmPersonGender convGender(str _gender)
{
    HcmPersonGender ret;
    #Define.Female("F")
    #Define.Male("M")
    ;
    switch (_gender)
    {
        case #Female:
            ret = HcmPersonGender::Female;
            break;

        case #Male:
            ret = HcmPersonGender::Male;
            break;

        default:
            ret = HcmPersonGender::None;
    }

    return ret;
}

static public Description createDescription(DirPersonName _dirPersonName)
{
    #Define.Space(" ")
    return _dirPersonName.FirstName
        + (_dirPersonName.MiddleName ? #Space + _dirPersonName.MiddleName : "")
        + (_dirPersonName.LastName   ? #Space + _dirPersonName.LastName   : "");
}
 

Adding Custom Dimension Values to the Custom Dimension using X++ Programming

static void AddingDimensionValuesForCustomDimension(Args _args)
{
    DimensionAttribute              dimensionAttribute;
    DimensionFinancialTag           dimensionFinancialTag;
    DimensionAttributeDirCategory   dimAttributeDirCategory;
    int64                           dirCategory;
    ;

    dimensionAttribute = dimensionAttribute::findByName("CUSTOMCOSTCENTER");// Custom Dimension
    // Only user defined dimensions will have a financial tag category
    if (dimensionAttribute.Type == DimensionAttributeType::CustomList)
    {
        select firstonly DirCategory from dimAttributeDirCategory where dimAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId;
         dirCategory = dimAttributeDirCategory.DirCategory;
    }
    DimensionFinancialTag.Value = "1000";//Custom Dimension Value
    DimensionFinancialTag.Description = "test"; // Custom Dimension Description
    DimensionFinancialTag.FinancialTagCategory = dirCategory;
    DimensionFinancialTag.insert();
}

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


Item Master ( Product Subtype---ProductMaster) import from CSV Using X++ Programming

AX
 In AX2012 we have to create the Records for ECOResProduct.

When we are creating the new product in form if you select the productsubtype as productMaster then we have to insert into the ECORESProductMaster and we have to pass this recid into the inventTable.

Ax classes are used to create the records for ECOResProduct

public class ProductMasterUpload extends RunBase
{

CommaIo csvFile;

Filename filename;

DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
container readCon;

counter icount,inserted;
Amount amount;
TransDate TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
NoYesID NoYes;
Ledgerjournalnameid Ledgerjournalnameid1,LedgerJournalNameId;
int cutoffdays,prevcutoffdays;
Amount AmountDB,AmountCR,CrCutOffAmountCalc,DrCutOffAmountCalc;
str AccountNum,date1;

args args;

EcoResProductVariantDimensionValue EcoResProductVariantDimensionValue;

RefRecId ecoResDistinctProductVariantRecId;

EcoResProductReleaseManagerBase releaseManager;
container productDimensions;

#define.CurrentVersion(2)

#localmacro.CurrentList

filename,

insertIncorrectRecords,

#endmacro

#localmacro.ListVersion1

filename,

insertIncorrectRecords

#endmacro

#File
}

public Object dialog()
{
DialogRunbase dialog = super();

;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));

dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files", #AllFiles]);
return dialog;
}

public boolean getFromDialog()
{

filename = dialogFilename.value();
return true;
}
static void main(Args args)
{

ProductMasterUpload ProductMasterUpload;

ledgerJournalTrans ledgerJournalTrans;

;
ProductMasterUpload = new ProductMasterUpload();

if(ProductMasterUpload.prompt())
{
ProductMasterUpload.ProductMasterNew(); 
}
}
private void ProductMasterNew()
{
CommaTextIo file;
container rec;

// ProductMaster

EcoResProductMaster ecoResProductMaster;

EcoResProductIdentifier ecoResProductIdentifier;

EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;

EcoResProductMasterModelingPolicy ecoResProductMasterModelingPolicy;

EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;

EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;

EcoResConfiguration ecoResConfiguration;

EcoResSize ecoResSize;

EcoResStyle ecoResStyle;

EcoResColor ecoResColor;

EcoResProductMasterConfiguration ecoResProductMasterConfiguration;

EcoResProductMasterSize ecoResProductMasterSize;

EcoResProductMasterStyle ecoResProductMasterStyle;

EcoResProductMasterColor ecoResProductMasterColor;

EcoResDistinctProductVariant ecoResDistinctProductVariant;

EcoResProductVariantConfiguration ecoResProductVariantConfiguration;

EcoResProductVariantSize ecoResProductVariantSize;

EcoResProductVariantStyle ecoResProductVariantStyle;

EcoResProductVariantColor ecoResProductVariantColor;

InventTable inventTable;

InventTableModule inventTableModule;

InventItemSetupSupplyType inventItemSetupSupplyType;

EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;

EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;

InventModelGroupItem inventModelGroupItem;

InventItemGroupItem inventItemGroupItem;

InventDim inventDim;

InventDimCombination inventDimCombination;

InventDim inventDim_InventSiteId;

InventDim inventDim_InventLocationId;

ItemId itemId;

EcoResProduct EcoResProduct;

EcoResCategory EcoResCategory;

EcoResCategoryHierarchy EcoResCategoryHierarchy;

EcoResCategoryAttribute ecoResCategoryAttribute;

EcoResAttribute ecoResAttribute;

EcoResProductAttributeValue EcoResProductAttributeValue;
  str name,productDimensionGroup,StorageDimensionGroup,TrackingDimensiongroup,modelGroupId,itemGroupId,unit,price,productCategory;

int64 productmasterrecid;

str 64PrdCategoryName,configid,colorid,sizeid,styleid,barcodeid,attributename,attributevalue,barcodesetupvalue,searchname,confignam,sizename,colorname,stylename;



inventItemBarCode inventItemBarCode;
// Product Master ends here
;
  csvFile = new CommaIO(filename, 'r');

try
{
    if (csvFile)
    {
         ttsbegin;


while (csvFile.status() == IO_Status::OK)
{

readCon = csvFile.read();

icount++;
if(icount == 1)

continue;

itemId = conPeek(readCon,1); //(_conLine,#InventTable_ItemId_ColumnNum);

name = conPeek(readCon,2);

productDimensionGroup = conPeek(readCon,3);

StorageDimensionGroup = conPeek(readCon,4);

TrackingDimensiongroup = conPeek(readCon,5);

modelGroupId = conPeek(readCon,6);

itemGroupId = conPeek(readCon,7);

unit = conPeek(readCon,8);

price = conPeek(readCon,9);

productCategory = conPeek(readCon,10);

PrdCategoryName = conPeek(readCon,11);

configid = conPeek(readCon,12);

colorid = conPeek(readCon,13);

Sizeid = conPeek(readCon,14);

styleid = conPeek(readCon,15);

barcodeid = conPeek(readCon,16);

Barcodesetupvalue = conPeek(readCon,17);

Searchname = conPeek(readCon,18);

confignam = conPeek(readCon,19);

sizename = conPeek(readCon,20);

stylename = conPeek(readCon,21);

colorname = conPeek(readCon,22);

if(!itemId)

continue;



inventTable= InventTable::find(itemId);
  //info(strFmt("%1 %2 %3 %4",configid,Sizeid,colorid,styleid));

if(inventTable)



this.Multilines(itemId,Sizeid,colorid,styleid,configid,searchname,barcodeid,unit,Barcodesetupvalue,name,confignam,sizename,stylename,colorname);
if(!inventTable)
{
  if (readCon && icount > 1 )//dont insert first record of file : header
{

ecoResProductMaster.clear();

ecoResProductMaster.initValue();

ecoResProductMaster.ProductType = EcoResProductType::Item;

ecoResProductMaster.DisplayProductNumber = itemId;

ecoResProductMaster.SearchName = searchname;

ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
if (ecoResProductMaster.validateWrite())
{

ecoResProductMaster.insert();

ecoResProductIdentifier.clear();

ecoResProductIdentifier.initValue();

ecoResProductIdentifier.ProductNumber = itemId;

ecoResProductIdentifier.Product = ecoResProductMaster.RecId;

ecoResProductIdentifier.insert();
  //Product dimension group



ecoResProductDimensionGroupProduct.clear();

ecoResProductDimensionGroupProduct.initValue();

ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);

ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(productDimensionGroup).RecId;
if (ecoResProductDimensionGroupProduct.validateWrite())
{

    ecoResProductDimensionGroupProduct.insert();

}
//Storage dimension group

ecoResStorageDimensionGroupProduct.clear();

ecoResStorageDimensionGroupProduct.initValue();

ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;

ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{

    ecoResStorageDimensionGroupProduct.insert();

}

ecoResTrackingDimensionGroupProduct.clear();

ecoResTrackingDimensionGroupProduct.initValue();

ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;

ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensiongroup).RecId;


if (ecoResTrackingDimensionGroupProduct.validateWrite())
{

    ecoResTrackingDimensionGroupProduct.insert();

}
//Product modeling policy
ecoResProductMasterModelingPolicy.clear();

ecoResProductMasterModelingPolicy.initValue();

ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId;
if (ecoResProductMasterModelingPolicy.validateWrite())
{

   ecoResProductMasterModelingPolicy.insert();

}
  //Product translation


EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, name, name);
  //Configuration



ecoResConfiguration = EcoResConfiguration::findByName(configid);
if (!ecoResConfiguration)
{

  ecoResConfiguration.clear();

  ecoResConfiguration.initValue();

  ecoResConfiguration.Name = configid;

  ecoResConfiguration.insert();

}
  // Size

ecoResSize = ecoResSize::findByName(sizeid);
if (!ecoResSize)
{

  ecoResSize.clear();

  ecoResSize.initValue();

  ecoResSize.Name = sizeid;

  ecoResSize.insert();

}
  // Style

ecoResStyle = ecoResStyle::findByName(styleid);
if (!ecoResStyle && styleid != "")
{

  ecoResStyle.clear();

  ecoResStyle.initValue();

  ecoResStyle.Name = styleid;

  ecoResStyle.insert();

}
// color
ecoResColor = ecoResColor::findByName(colorid);
if (!ecoResColor)
{

  ecoResColor.clear();

  ecoResColor.initValue();

  ecoResColor.Name = colorid;

  ecoResColor.insert();

}


//Configuration assigned to product master



ecoResProductMasterConfiguration.clear();

ecoResProductMasterConfiguration.initValue();

ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;

ecoResProductMasterConfiguration.Description = confignam;
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));



ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;

ecoResProductMasterConfiguration.insert();
  //Sizes assigned to product master



ecoResProductMasterSize.clear();

ecoResProductMasterSize.initValue();

ecoResProductMasterSize.Size = ecoResSize.RecId;

ecoResProductMasterSize.Description = sizename;
  ecoResProductMasterSize.SizeProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId));



ecoResProductMasterSize.SizeProductMaster = ecoResProductMaster.RecId;

ecoResProductMasterSize.insert();
  //Style assigned to product master



ecoResProductMasterStyle.clear();

ecoResProductMasterStyle.initValue();
  ecoResProductMasterStyle.Style = ecoResStyle.RecId;//.RecId;



ecoResProductMasterStyle.Description = stylename;
  ecoResProductMasterStyle.StyleProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));



ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;

ecoResProductMasterStyle.insert();
  //Color assigned to product master



ecoResProductMasterColor.clear();

ecoResProductMasterColor.initValue();
  ecoResProductMasterColor.Color = ecoRescolor.RecId;//.RecId;



ecoResProductMasterColor.Description = colorname;
  ecoResProductMasterColor.ColorProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));



ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;

ecoResProductMasterColor.insert();
  //Product variant



ecoResDistinctProductVariant.clear();

ecoResDistinctProductVariant.initValue();

ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(

ecoResProductMaster.productNumber(),

EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name, ecoResSize.Name, ecoResColor.Name,ecoResStyle.Name));
  ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName;// + ItemId/*ConfigId*/;



ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;

ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;

ecoResDistinctProductVariant.insert();


  //Product variant configuration



ecoResProductVariantConfiguration.clear();

ecoResProductVariantConfiguration.initValue();

ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
  ecoResProductVariantConfiguration.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));



ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;

ecoResProductVariantConfiguration.insert();

 
  //Size variant configuration



ecoResProductVariantSize.clear();

ecoResProductVariantSize.initValue();

ecoResProductVariantSize.initFromDistinctProductVariant(ecoResDistinctProductVariant);
  ecoResProductVariantSize.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeid));



ecoResProductVariantSize.Size = ecoResSize.RecId;

ecoResProductVariantSize.insert();

 
  //Style variant configuration



ecoResProductVariantStyle.clear();

ecoResProductVariantStyle.initValue();

ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
  ecoResProductVariantStyle.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleid));



ecoResProductVariantStyle.Style = ecoResStyle.RecId;

ecoResProductVariantStyle.insert();

 
  //Color variant configuration



ecoResProductVariantColor.clear();

ecoResProductVariantColor.initValue();

ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
  ecoResProductVariantColor.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));



ecoResProductVariantColor.Color = ecoResColor.RecId;

ecoResProductVariantColor.insert();

 
  //Product variant translation



EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId, name, name);


  //Released product



inventTable.clear();

inventTable.initValue();

inventTable.initFromEcoResProduct(ecoResProductMaster);

inventTable.ItemId = ItemId;

inventTable.NameAlias = searchname;

inventTable.CostModel = NoYes::Yes;

inventTable.PurchModel = NoYes::Yes;
if (inventTable.validateWrite())
{

  inventTable.insert();
  //Inventory model group



  inventModelGroupItem.clear();

  inventModelGroupItem.initValue();
 
  inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;

  inventModelGroupItem.ItemId = inventTable.ItemId;

  inventModelGroupItem.ModelGroupId = modelGroupId;
  inventModelGroupItem.ModelGroupDataAreaId = curext();



  inventModelGroupItem.insert();

 
  //Item group
  inventItemGroupItem.clear();

  inventItemGroupItem.initValue();

  inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;

  inventItemGroupItem.ItemId = inventTable.ItemId;

  inventItemGroupItem.ItemGroupId = itemGroupId;
  inventItemGroupItem.ItemGroupDataAreaId = curext();



  inventItemGroupItem.insert();

 
  //Extended product details - Inventory
  inventTableModule.clear();

  inventTableModule.initValue();

  inventTableModule.ItemId = inventTable.ItemId;

  inventTableModule.ModuleType = ModuleInventPurchSales::Invent;

  inventTableModule.UnitId = unit;
  inventTableModule.Price = any2real(price);
  inventTableModule.insert();

 
  //Extended product details - Purchase
  inventTableModule.clear();

  inventTableModule.initValue();

  inventTableModule.ItemId = inventTable.ItemId;

  inventTableModule.ModuleType = ModuleInventPurchSales::Purch;

  inventTableModule.UnitId = unit;
  //inventTableModule.Price = any2real(price);
  inventTableModule.insert();

  //Extended product details - Sales
  inventTableModule.clear();

  inventTableModule.initValue();

  inventTableModule.ItemId = inventTable.ItemId;

  inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
  inventTableModule.Price = any2real(price);



inventTableModule.insert();
  //Warehouse items

InventItemLocation::createDefault(inventTable.ItemId);
  //Supply type setup

inventItemSetupSupplyType.clear();

inventItemSetupSupplyType.initValue();

inventItemSetupSupplyType.ItemId = inventTable.ItemId;

inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;

inventItemSetupSupplyType.insert();


//Product storage dimension group
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{

  ecoResStorageDimensionGroupItem.clear();

  ecoResStorageDimensionGroupItem.initValue();

  ecoResStorageDimensionGroupItem.ItemDataAreaId =      inventTable.DataAreaId;

  ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;

  ecoResStorageDimensionGroupItem.StorageDimensionGroup =   ecoResStorageDimensionGroupProduct.StorageDimensionGroup;

  ecoResStorageDimensionGroupItem.insert();

}
  //Product tracking dimension group



ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
  if (ecoResTrackingDimensionGroupProduct.RecId)



{

ecoResTrackingDimensionGroupItem.clear();

ecoResTrackingDimensionGroupItem.initValue();

ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;

ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;

ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;

ecoResTrackingDimensionGroupItem.insert();

}
  //Product Category



EcoResProduct = EcoResProduct::findByDisplayProductNumber(itemid);
  EcoResCategoryHierarchy = EcoResCategoryHierarchy::findByName(PrdCategoryName);//"Procurement Hierarchy 1");//"Retail Product Category");//"Procurement Hierarchy 1"); // category hierarchy

EcoResCategory = EcoResCategory::findByName(productCategory,EcoResCategoryHierarchy.RecId); // category



EcoResProductCategory::insertEcoResProductCategory(EcoResCategory,EcoResProduct);



}


  ecoResDistinctProductVariant = ecoResDistinctProductVariant::find(ecoResDistinctProductVariant.RecId);//RecId);

//Now release the Product variant



releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);

releaseManager.release();
  select inventDim where inventDim.configId == configid



&& inventDim.InventSizeId == sizeid

&& inventDim.InventColorId == colorid

&& inventDim.InventStyleId == styleid;

inventDimCombination = inventDimCombination::find(itemid,inventDim.inventDimId);

inventItemBarCode.itemId = itemid;
  inventItemBarCode.barcodeSetupId = "EAN128";



inventItemBarCode.inventDimId = inventDim.inventDimId;

inventItemBarCode.itemBarCode = barcodeid;

inventItemBarCode.RetailVariantId = inventDimCombination.RetailVariantId;

inventItemBarCode.useForInput = NoYes::Yes;

inventItemBarCode.useForPrinting = NoYes::Yes;

inventItemBarCode.UnitID = unit;

inventItemBarCode.insert();



inserted++;
}
}
}
}
ttsCommit;


}
  
icount--;//Remove header recount from total record count

}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}

 

 
private void Multilines(ItemId itemid,str 64 inventsize, str 64 inventcolor, str 64 inventstyle, str 64 config,str 64 name,str 64 Barcodeidd,str unit,str barcodesetuppvalue,str productname,str confignam,str sizename,str stylename,str colorname)
{
EcoResConfiguration ecoResConfiguration;
EcoResSize ecoResSize;
EcoResStyle ecoResStyle;
EcoResColor ecoResColor;
EcoResProductMasterConfiguration ecoResProductMasterConfiguration;
EcoResProductMasterSize ecoResProductMasterSize;
EcoResProductMasterStyle ecoResProductMasterStyle;
EcoResProductMasterColor ecoResProductMasterColor;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantConfiguration ecoResProductVariantConfiguration;
EcoResProductVariantSize ecoResProductVariantSize;
EcoResProductVariantStyle ecoResProductVariantStyle;
EcoResProductVariantColor ecoResProductVariantColor;
ecoResProductMaster ecoResProductMaster;
InventTable inventtable;
InventDimCombination inventDimCombination;
InventDim inventDim;
InventItemBarcode inventItemBarCode;
;


select inventtable where inventtable.ItemId == itemid
join ecoResProductMaster where ecoResProductMaster.SearchName == name;
//Configuration
ecoResConfiguration = EcoResConfiguration::findByName(config);
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = config;
ecoResConfiguration.insert();
}
// Size
ecoResSize = ecoResSize::findByName(inventsize);
if (!ecoResSize)
{
ecoResSize.clear();
ecoResSize.initValue();
ecoResSize.Name = inventsize;
ecoResSize.insert();
}
// Style
ecoResStyle = ecoResStyle::findByName(inventstyle);
if (!ecoResStyle && inventstyle !="")
{
ecoResStyle.clear();
ecoResStyle.initValue();
ecoResStyle.Name = inventstyle;
ecoResStyle.insert();
}
 
// color
ecoResColor = ecoResColor::findByName(inventcolor);
if (!ecoResColor)
{
ecoResColor.clear();
ecoResColor.initValue();
ecoResColor.Name = inventcolor;
ecoResColor.insert();
}


//Configuration assigned to product master
select ecoResProductMasterConfiguration where ecoResProductMasterConfiguration.Configuration == ecoResConfiguration.RecId
&& ecoResProductMasterConfiguration.ConfigProductMaster == ecoResProductMaster.RecId;

if(!ecoResProductMasterConfiguration && config != "")
{
ecoResProductMasterConfiguration.clear();
ecoResProductMasterConfiguration.initValue();
ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductMasterConfiguration.Description = confignam;
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterConfiguration.insert();
}
//Sizes assigned to product master


select ecoResProductMasterSize where ecoResProductMasterSize.Size == ecoResSize.RecId
&& ecoResProductMasterSize.SizeProductMaster == ecoResProductMaster.RecId;
if(!ecoResProductMasterSize && inventsize != "")
{
ecoResProductMasterSize.clear();
ecoResProductMasterSize.initValue();
ecoResProductMasterSize.Size = ecoResSize.RecId;
ecoResProductMasterSize.Description = sizename;
ecoResProductMasterSize.SizeProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId));
ecoResProductMasterSize.SizeProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterSize.insert();
}


//Style assigned to product master


select ecoResProductMasterStyle where ecoResProductMasterStyle.Style == ecoResStyle.RecId
&& ecoResProductMasterStyle.StyleProductMaster == ecoResProductMaster.RecId;
if(!ecoResProductMasterStyle && inventstyle != "")
{
ecoResProductMasterStyle.clear();
ecoResProductMasterStyle.initValue();
ecoResProductMasterStyle.Style = ecoResStyle.RecId;//.RecId;
ecoResProductMasterStyle.Description = stylename;
ecoResProductMasterStyle.StyleProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterStyle.insert();
}
//Color assigned to product master
select ecoResProductMasterColor where ecoResProductMasterColor.Color == ecoRescolor.RecId
&& ecoResProductMasterColor.ColorProductMaster == ecoResProductMaster.RecId ;


if(!ecoResProductMasterColor && inventcolor != "")
{
ecoResProductMasterColor.clear();
ecoResProductMasterColor.initValue();
ecoResProductMasterColor.Color = ecoRescolor.RecId;//.RecId;
ecoResProductMasterColor.Description = colorname;
ecoResProductMasterColor.ColorProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterColor.insert();
}

//Product variant
ecoResDistinctProductVariant.clear();
ecoResDistinctProductVariant.initValue();
ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
ecoResProductMaster.productNumber(),
EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,ecorescolor.Name,ecoresstyle.Name));
ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName;// +
ItemId/*ConfigId*/;
ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
ecoResDistinctProductVariant.insert();
//Product variant configuration
ecoResProductVariantConfiguration.clear();
ecoResProductVariantConfiguration.initValue();
ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantConfiguration.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductVariantConfiguration.insert();
//Size variant configuration
ecoResProductVariantSize.clear();
ecoResProductVariantSize.initValue();
ecoResProductVariantSize.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantSize.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeid));
ecoResProductVariantSize.Size = ecoResSize.RecId;
ecoResProductVariantSize.insert();
//Style variant configuration
ecoResProductVariantStyle.clear();
ecoResProductVariantStyle.initValue();
ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantStyle.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleid));
ecoResProductVariantStyle.Style = ecoResStyle.RecId;
ecoResProductVariantStyle.insert();
//Color variant configuration
ecoResProductVariantColor.clear();
ecoResProductVariantColor.initValue();
ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantColor.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductVariantColor.Color = ecoResColor.RecId;
ecoResProductVariantColor.insert();
//Product variant translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId, productname, productname);
//Find newly created Product Variant
ecoResDistinctProductVariant = ecoResDistinctProductVariant::find(ecoResDistinctProductVariant.RecId);//RecId);
//Now release the Product variant
releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
select inventDim where inventDim.configId == config
&& inventDim.InventSizeId == inventsize
&& inventDim.InventColorId == inventcolor
&& inventDim.InventStyleId == inventstyle;
inventDimCombination = inventDimCombination::find(itemid,inventDim.inventDimId);
inventItemBarCode.itemId = itemid;
inventItemBarCode.barcodeSetupId = barcodesetuppvalue;//"EAN128";
inventItemBarCode.inventDimId = inventDim.inventDimId;
inventItemBarCode.itemBarCode = barcodeidd;
inventItemBarCode.RetailVariantId = inventDimCombination.RetailVariantId;
inventItemBarCode.useForInput = NoYes::Yes;
inventItemBarCode.useForPrinting = NoYes::Yes;
inventItemBarCode.UnitID = unit;
inventItemBarCode.insert();
}

  


Item Master ( Product Subtype---Product) import from CSV file using X++ Programming



AX
    In AX2012 we have to create the Records for ECOResProduct.

When the productSubtype is Products then we have to use EcoResdistinctProduct and pass the recid to inventTable and AX classes are used to save the records into the Tables.

public class ItemMasterImport extends RunBase
{

CommaIo                                    csvFile;
Filename                                   filename;
DialogField                                dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
container                                  readCon;
counter                                    icount,inserted;
TransDate                                  TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
NoYesID                                    NoYes;
str                                        AccountNum,date1;
args                                       args;
EcoResProductVariantDimensionValue         EcoResProductVariantDimensionValue;
RefRecId                                   ecoResDistinctProductVariantRecId;
EcoResProductReleaseManagerBase   releaseManager;
container productDimensions;

#define.CurrentVersion(
2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
 
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(
extendedTypeStr(FilenameOpen));

dialogFilename.value(filename);
dialog.filenameLookupFilter([
"All files", #AllFiles]);
return dialog;
}

public boolean getFromDialog()
{
filename = dialogFilename.value();return true;
}

static void main(Args args)
{
ItemMasterImport ItemMasterImport;

ItemMasterImport = new ItemMasterImport();

if(ItemMasterImport.prompt())
{
  itemMasterImport.ItemMasterUpload();

}
}

void ItemMasterUpload()

{
AxInventTable axInventTable;

AxInventItemGroupItem axInventGroupItem;

AxInventModelGroupItem axInventModelGroupItem;

AxInventTableModule AxInventTableModule;

AxInventTableModule axInventTableModulePurch ,axInventTableModuleInvent;

AxEcoResProductTranslation axProductTranslation;

AxInventItemInventSetup axInventItemInventSetup;

AxInventItemPurchSetup axInventItemPurchSetup;

axInventItemSalesSetup axInventItemSalesSetup;

InventItemSetupSupplyType inventItemSetupSupplyType;

EcoResDistinctProduct ecoResDistictProduct;

EcoResProduct EcoResProduct;

EcoResCategory EcoResCategory;

EcoResCategoryHierarchy EcoResCategoryHierarchy;

ItemId itemId;

InventTable inventTable;

InventItemGroupItem inventItemGroupItem;

Dialog d;

DialogField df1;

CommaTextIo file;
container rec;

InventDim inventDim_InventSiteId;

InventDim inventDim_InventLocationId;
strsearchname,nameAlias,unitid,itemGroupId,modelGroupId,storageDimensionGroup,trackingDimensionGroup,CategoryHierarchyName,CategoryName,purchPrice,salesPrice;

;
 
csvFile = new CommaIO(filename, 'r');

try
{
if (csvFile)
{
ttsbegin;

while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if (readCon)
{
readCon = csvFile.read();// To remove the first record of file : header

itemId =
 conPeek(readCon,1); 

Searchname =
 conPeek(readCon,2); 

NameAlias =
 conPeek(readCon,3); 

ItemGroupId =
 conPeek(readCon,4); 

ModelGroupId =
 conPeek(readCon,5); 

StorageDimensionGroup =
 conPeek(readCon,6); 

TrackingDimensionGroup =
 conPeek(readCon,7); 

UnitID =
 conPeek(readCon,8); 

CategoryHierarchyName =
 conPeek(readCon,9);

CategoryName =
 conPeek(readCon,10);

purchPrice =
 conPeek(readCon,11);

salesPrice =
 conPeek(readCon,12);

if(!itemId)

continue;

inventTable= InventTable::find(itemId); 
 if(!inventTable)

{
ecoResDistictProduct.clear();

ecoResDistictProduct.initValue();

ecoResDistictProduct.DisplayProductNumber=itemId;

ecoResDistictProduct.ProductType=ecoResProductType::Item;
 ecoResDistictProduct.SearchName= Searchname;

ecoResDistictProduct.insert();


ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = itemId;
ecoResProductIdentifier.Product = ecoResDistictProduct.RecId;

ecoResProductIdentifier.insert();

axInventTable=axInventTable::construct();                       

axInventTable.parmItemId(itemId); 
axInventTable.parmItemType(ItemType::Item);
axInventTable.parmProduct(ecoResDistictProduct.RecId);
 axInventTable.parmNameAlias(NameAlias); 

//InventTableModulePurch
axInventTableModulePurch = AxInventTableModule::construct();

axInventTableModulePurch.axInventTable(axInventTable);

axInventTableModulePurch.parmItemId(itemId);

axInventTableModulePurch.parmModuleType(ModuleInventPurchSales::Purch);

axInventTableModulePurch.parmUnitId(UnitID);
 axInventTableModulePurch.parmPrice(str2int(purchPrice));

axInventTable.axInventTableModule_Purch(axInventTableModulePurch);

//InventTableModuleInvent


axInventTableModuleInvent = AxInventTableModule::construct();

axInventTableModuleInvent.axInventTable(axInventTable);

axInventTableModuleInvent.parmItemId(itemId);

axInventTableModuleInvent.parmModuleType(ModuleInventPurchSales::Invent);

axInventTableModuleInvent.parmUnitId(UnitID);
 axInventTableModuleInvent.parmPrice(str2int(salesPrice));

axInventTable.axInventTableModule_Invent(axInventTableModuleInvent);

axInventTable.save();
 
//InventGroup Item

axInventGroupItem=AxInventItemGroupItem::construct();

axInventGroupItem.parmItemId(itemId);                       
axInventGroupItem.parmItemGroupId(ItemGroupId); 
axInventGroupItem.parmItemGroupDataAreaId(
curext());

axInventGroupItem.parmItemDataAreaId(
curext());

axInventGroupItem.save();                      

//InventModelGroupItem


axInventModelGroupItem=AxInventModelGroupItem::construct();

axInventModelGroupItem.parmItemId(itemId);

axInventModelGroupItem.parmModelGroupId(ModelGroupId);
 axInventModelGroupItem.parmModelGroupDataAreaId(curext());

axInventModelGroupItem.parmItemDataAreaId(
curext());

axInventModelGroupItem.save();
 

axProductTranslation=AxEcoResProductTranslation::construct();                       
axProductTranslation.parmDescription(searchname); 
axProductTranslation.parmName(searchname);
 
axProductTranslation.parmProduct(ecoResDistictProduct.RecId);
 axProductTranslation.parmLanguageId("en-us");

axProductTranslation.save();                       

//Storage and Tracking dimension

inventTable= InventTable::find(itemId,
true);

InventTableInventoryDimensionGroups::updateDimensionGroupsForItem(
 curext(), itemid, EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId,

EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensionGroup).RecId,

inventtable.product);
//Product Category

EcoResProduct = EcoResProduct::findByDisplayProductNumber(itemid);
 EcoResCategoryHierarchy = EcoResCategoryHierarchy::findByName(CategoryHierarchyName); // category hierarchy

EcoResCategory = EcoResCategory::findByName(CategoryName,EcoResCategoryHierarchy.RecId);
 // category

EcoResProductCategory::insertEcoResProductCategory(EcoResCategory,EcoResProduct);
axInventItemInventSetup = AxInventItemInventSetup::newInventItemInventSetup(InventItemInventSetup::findDefault(itemId,
 true));

axInventItemInventSetup.axInventTable(axInventTable);

axInventItemInventSetup.parmInventDimIdDefault(inventDim_InventSiteId.InventDimId);

axInventItemInventSetup.save();

axInventItemInventSetup = AxInventItemInventSetup::construct();

axInventItemInventSetup.axInventTable(axInventTable);

axInventItemInventSetup.parmItemId(itemId);

axInventItemInventSetup.parmInventDimId(inventDim_InventSiteId.inventDimId);

axInventItemInventSetup.parmInventDimIdDefault(inventDim_InventLocationId.InventDimId);

axInventItemInventSetup.save();                       

//InventItemPurchaseSetup

axInventItemPurchSetup = axInventItemPurchSetup::newInventItemPurchSetup(InventItemPurchSetup::findDefault(itemId,
 true));

axInventItemPurchSetup.axInventTable(axInventTable);

axInventItemPurchSetup.parmInventDimIdDefault(inventDim_InventSiteId.InventDimId);

axInventItemPurchSetup.save();

axInventItemPurchSetup = AxInventItemPurchSetup::construct();

axInventItemPurchSetup.axInventTable(axInventTable);

axInventItemPurchSetup.parmItemId(itemId);

axInventItemPurchSetup.parmInventDimId(inventDim_InventSiteId.inventDimId);

axInventItemPurchSetup.parmInventDimIdDefault(inventDim_InventLocationId.InventDimId);

axInventItemPurchSetup.save();                       

//InventItemSalesSetup

axInventItemSalesSetup = AxInventItemSalesSetup::newInventItemSalesSetup(InventItemSalesSetup::findDefault(itemId,
 true));

axInventItemSalesSetup.axInventTable(axInventTable);

axInventItemSalesSetup.parmInventDimIdDefault(inventDim_InventSiteId.InventDimId);

axInventItemSalesSetup.save();

axInventItemSalesSetup = AxInventItemSalesSetup::construct();

axInventItemSalesSetup.axInventTable(axInventTable);

axInventItemSalesSetup.parmItemId(itemId);

axInventItemSalesSetup.parmInventDimId(inventDim_InventSiteId.inventDimId);

axInventItemSalesSetup.parmInventDimIdDefault(inventDim_InventLocationId.InventDimId);

axInventItemSalesSetup.save();

inserted++;

}
 }
    }
   ttsCommit;
    } 
icount--;//Remove header recount from total record count
    } 
    catch(Exception::Error)
    {
 info(strFmt("%1 %2",Exception::Error,icount));
    }

}