I am posting only the method where the Input was Container.
Before using this code write your logic to read the CSV file using COMMAIO and get the container and pass to the below method.
And I created the Macro with the position numbers that i used in the below code.
I am using the AX classes to save the records into the Tables.
In AX2012 we have to create the Records for ECOResProduct.
ECOResProduct is the abstract Table and the following tables are inherited from this.
ECORESProductMaster,EcoResdistinctProduct.
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.
When the productSubtype is Products then we have to use EcoResdistinctProduct and pass the recid to inventTable.
Below I am using the Products.
Macro:-
//InventTable
Public class Krishh_ImportItem
{
//Macro which contains the column positions.
#ItemImport
AxInventTable axInventTable;
AxInventItemGroupItem axInventGroupItem;
AxInventModelGroupItem axInventModelGroupItem;
AxEcoResProductTranslation axProductTranslation;
AxInventItemInventSetup axInventItemInventSetup;
AxInventItemPurchSetup axInventItemPurchSetup;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResDistinctProduct ecoResDistictProduct;
}
protected void createInventTable(container _conLine)
{
ItemId itemId;
InventTable inventTable;
InventItemGroupItem inventItemGroupItem;
;
itemId = this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum);
inventTable= InventTable::find(itemId);
if(!inventTable)
{
ecoResDistictProduct.clear();
ecoResDistictProduct.initValue();
ecoResDistictProduct.DisplayProductNumber=itemId;
ecoResDistictProduct.ProductType=ecoResProductType::Item;
ecoResDistictProduct.SearchName=this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum);
ecoResDistictProduct.insert();
axInventTable=axInventTable::construct();
axInventTable.parmItemId(this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum));
axInventTable.parmItemType(ItemType::Item);
axInventTable.parmPrimaryVendorId(this.getLineValue(_conLine,#InventTable_PrimaryVendorId_ColumnNum));
axInventTable.parmNetWeight(this.getLineValue(_conLine,#InventTable_NetWeight_ColumnNum));
axInventTable.parmProduct(ecoResDistictProduct.RecId);
axInventTable.parmUnitVolume(this.getLineValue(_conLine,#InventTable_UnitVolume_ColumnNum));
axInventTable.parmUseAltItemId(ItemNumAlternative::Always);
axInventTable.parmAltItemId(this.getLineValue(_conLine,#InventTable_AltItemId_ColumnNum));
axInventTable.parmIntracode(this.getLineValue(_conLine,#InventTable_Intracode_ColumnNum));
axInventTable.parmABCRevenue(this.getLineValue(_conLine,#InventTable_ABCRevenue_ColumnNum));
axInventTable.parmNameAlias(this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum));
axInventTable.parmClassification(this.getLineValue(_conLine,#InventTable_Classification_ColumnNum));
//TODO uncomment once the parm methods where builded
// axInventTable.parmIntegration(this.getLineValue(_conLine,#InventTable_Integration_ColumnNum));
// axInventTable.parmRevisionId(this.getLineValue(_conLine,#InventTable_RevisionId_ColumnNum));
//InventItemInventSetup
axInventItemInventSetup=AxInventItemInventSetup::construct();
axInventItemInventSetup.parmItemId(itemId);
axInventItemInventSetup.parmLowestQty(this.getLineValue(_conLine,#InventItemInvent_LowestQty_ColumnNum));
axInventItemInventSetup.parmHighestQty(this.getLineValue(_conLine,#InventItemInvent_HighestQty_ColumnNum));
axInventItemInventSetup.parmStandardQty(this.getLineValue(_conLine,#InventItemInvent_StandardQty_ColumnNum));
axInventTable.axInventItemInventSetup(axInventItemInventSetup);
//
//////InventPurchSetup
axInventItemPurchSetup=AxInventItemPurchSetup::construct();
axInventItemPurchSetup.parmItemId(itemId);
axInventTable.axInventItemPurchSetup(axInventItemPurchSetup);
axInventTable.save();
//InventGroup Item
axInventGroupItem=AxInventItemGroupItem::construct();
axInventGroupItem.parmItemId(itemId);
axInventGroupItem.parmItemGroupId(this.getLineValue(_conLine,#InventItemGroupItem_ItemGroupId_ColumnNum));
axInventGroupItem.parmItemGroupDataAreaId(curext());
axInventGroupItem.save();
//InventModelGroupItem
axInventModelGroupItem=AxInventModelGroupItem::construct();
axInventModelGroupItem.parmItemId(itemId);
axInventModelGroupItem.parmModelGroupId("Std Cost");
axInventModelGroupItem.parmModelGroupDataAreaId(curext());
axInventModelGroupItem.save();
//Product Translation
axProductTranslation=AxEcoResProductTranslation::construct();
axProductTranslation.parmDescription(this.getLineValue(_conLine,#EcoResProductTranslationENG_Description_ColumnNum));
axProductTranslation.parmName(this.getLineValue(_conLine,#EcoResProductTranslationENG_Name_ColumnNum));
axProductTranslation.parmProduct(ecoResDistictProduct.RecId);
axProductTranslation.save();
//InventItemSetupSupplyType
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.DefaultOrderType=ReqPOType::Purch;
inventItemSetupSupplyType.ItemId=itemId;
inventItemSetupSupplyType.ItemDataAreaId=curext();
inventItemSetupSupplyType.insert();
}
}
Before using this code write your logic to read the CSV file using COMMAIO and get the container and pass to the below method.
And I created the Macro with the position numbers that i used in the below code.
I am using the AX classes to save the records into the Tables.
In AX2012 we have to create the Records for ECOResProduct.
ECOResProduct is the abstract Table and the following tables are inherited from this.
ECORESProductMaster,EcoResdistinctProduct.
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.
When the productSubtype is Products then we have to use EcoResdistinctProduct and pass the recid to inventTable.
Below I am using the Products.
Macro:-
//InventTable
#define.InventTable_ItemId_ColumnNum(1)
#define.InventTable_PrimaryVendorId_ColumnNum(2)
#define.InventTable_NetWeight_ColumnNum(3)
#define.InventTable_UnitVolume_ColumnNum(4)
#define.InventTable_AltItemId_ColumnNum(5)
#define.InventTable_Intracode_ColumnNum(6)
#define.InventTable_ABCRevenue_ColumnNum(7)
#define.InventTable_NameAlias_ColumnNum(8)
#define.InventTable_Classification_ColumnNum(9)
#define.InventTable_Integration_ColumnNum(10)
//InventItemLocation
columns
#define.InventItemLocation_ItemId_ColumnNum(11)
//Invent
GroupItem
#define.InventItemGroupItem_ItemId_ColumnNum(12)
#define.InventItemGroupItem_ItemGroupId_ColumnNum(13)
//InventModelGroupItem
#define.InventModelGroupItem_ItemId_ColumnNum(14)
//ECOResProduct
translation for english
#define.EcoResProductTranslationENG_Description_ColumnNum(15)
#define.EcoResProductTranslationENG_Name_ColumnNum(16)
//InventItemPurchSetup
for default order settings
#define.InventItemPurch_ItemId_ColumnNum(17)
//inventItemInventSetup
for Default order settings
#define.InventItemInvent_ItemId_ColumnNum(18)
#define.InventItemInvent_LowestQty_ColumnNum(19)
#define.InventItemInvent_HighestQty_ColumnNum(20)
#define.InventItemInvent_StandardQty_ColumnNum(21)
//InventItemSupplySetup
#define.InventItemSetupSupplytype_ItemId_ColumnNum(22)
Public class Krishh_ImportItem
{
//Macro which contains the column positions.
#ItemImport
AxInventTable axInventTable;
AxInventItemGroupItem axInventGroupItem;
AxInventModelGroupItem axInventModelGroupItem;
AxEcoResProductTranslation axProductTranslation;
AxInventItemInventSetup axInventItemInventSetup;
AxInventItemPurchSetup axInventItemPurchSetup;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResDistinctProduct ecoResDistictProduct;
}
protected void createInventTable(container _conLine)
{
ItemId itemId;
InventTable inventTable;
InventItemGroupItem inventItemGroupItem;
;
itemId = this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum);
inventTable= InventTable::find(itemId);
if(!inventTable)
{
ecoResDistictProduct.clear();
ecoResDistictProduct.initValue();
ecoResDistictProduct.DisplayProductNumber=itemId;
ecoResDistictProduct.ProductType=ecoResProductType::Item;
ecoResDistictProduct.SearchName=this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum);
ecoResDistictProduct.insert();
axInventTable=axInventTable::construct();
axInventTable.parmItemId(this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum));
axInventTable.parmItemType(ItemType::Item);
axInventTable.parmPrimaryVendorId(this.getLineValue(_conLine,#InventTable_PrimaryVendorId_ColumnNum));
axInventTable.parmNetWeight(this.getLineValue(_conLine,#InventTable_NetWeight_ColumnNum));
axInventTable.parmProduct(ecoResDistictProduct.RecId);
axInventTable.parmUnitVolume(this.getLineValue(_conLine,#InventTable_UnitVolume_ColumnNum));
axInventTable.parmUseAltItemId(ItemNumAlternative::Always);
axInventTable.parmAltItemId(this.getLineValue(_conLine,#InventTable_AltItemId_ColumnNum));
axInventTable.parmIntracode(this.getLineValue(_conLine,#InventTable_Intracode_ColumnNum));
axInventTable.parmABCRevenue(this.getLineValue(_conLine,#InventTable_ABCRevenue_ColumnNum));
axInventTable.parmNameAlias(this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum));
axInventTable.parmClassification(this.getLineValue(_conLine,#InventTable_Classification_ColumnNum));
//TODO uncomment once the parm methods where builded
// axInventTable.parmIntegration(this.getLineValue(_conLine,#InventTable_Integration_ColumnNum));
// axInventTable.parmRevisionId(this.getLineValue(_conLine,#InventTable_RevisionId_ColumnNum));
//InventItemInventSetup
axInventItemInventSetup=AxInventItemInventSetup::construct();
axInventItemInventSetup.parmItemId(itemId);
axInventItemInventSetup.parmLowestQty(this.getLineValue(_conLine,#InventItemInvent_LowestQty_ColumnNum));
axInventItemInventSetup.parmHighestQty(this.getLineValue(_conLine,#InventItemInvent_HighestQty_ColumnNum));
axInventItemInventSetup.parmStandardQty(this.getLineValue(_conLine,#InventItemInvent_StandardQty_ColumnNum));
axInventTable.axInventItemInventSetup(axInventItemInventSetup);
//
//////InventPurchSetup
axInventItemPurchSetup=AxInventItemPurchSetup::construct();
axInventItemPurchSetup.parmItemId(itemId);
axInventTable.axInventItemPurchSetup(axInventItemPurchSetup);
axInventTable.save();
//InventGroup Item
axInventGroupItem=AxInventItemGroupItem::construct();
axInventGroupItem.parmItemId(itemId);
axInventGroupItem.parmItemGroupId(this.getLineValue(_conLine,#InventItemGroupItem_ItemGroupId_ColumnNum));
axInventGroupItem.parmItemGroupDataAreaId(curext());
axInventGroupItem.save();
//InventModelGroupItem
axInventModelGroupItem=AxInventModelGroupItem::construct();
axInventModelGroupItem.parmItemId(itemId);
axInventModelGroupItem.parmModelGroupId("Std Cost");
axInventModelGroupItem.parmModelGroupDataAreaId(curext());
axInventModelGroupItem.save();
//Product Translation
axProductTranslation=AxEcoResProductTranslation::construct();
axProductTranslation.parmDescription(this.getLineValue(_conLine,#EcoResProductTranslationENG_Description_ColumnNum));
axProductTranslation.parmName(this.getLineValue(_conLine,#EcoResProductTranslationENG_Name_ColumnNum));
axProductTranslation.parmProduct(ecoResDistictProduct.RecId);
axProductTranslation.save();
//InventItemSetupSupplyType
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.DefaultOrderType=ReqPOType::Purch;
inventItemSetupSupplyType.ItemId=itemId;
inventItemSetupSupplyType.ItemDataAreaId=curext();
inventItemSetupSupplyType.insert();
}
}
I would like to insert AgreementLine which is abstract table. I tried to insert derived tables and the agreementLine but still didn't work out is there any other way or is there any class.
ReplyDeleteHi,
DeleteYou cannot insert into the agreementLine Table, Its abstract class, you have to insert into the derivice tables like-AgreementLineQuantityCommitment or AgreementLineVolumeCommitment
These two will be differentiated by
purchAgreementForm.parmDefaultCommitmentType() == CommitmentType::ProductQuantity or volume.
I hope this will help you to solve your problem.
Thanks,
Krishna.
Yes i had inserted now in AgreementLineQuantityCommitment but after insertion.
ReplyDeleteRecords are not showing up in PurchAgreement Form.
Yet if i refresh the PurchAgreementListpage iam able to get those records in that form.
I checked table both agreementLine and agreementQuantinty are inserted properly but recVersion was 1 in agreementLine how do i correct this.
why the records or not showing up? in purchAgreement
Form.
I dont think Recversion have an issue, It will create as version 1 only.May be you are missing the InstanceRelationType field in the AgreementLine table where you have to fill in the tableid of AgreementLineQuantityCommitment.
Deleteas well you have to fill the agreement header recid in the Agreement field of AgreementLine table. then it will show the data when you open the agreement form.
Hope this will help you.
thanks
krishna.
I checked DimID,Agreement,InstanceRelationType all are mapped like correctly. In PurchLisPage they are using Query Parts to Show lines which is able to display all lines.
ReplyDeleteBut in PurchAgreement they are using datasource which is not showing newly created records through code.
agreementLineQuantityCommitment.clear();
agreementLineQuantityCommitment.initValue();
agreementLineQuantityCommitment.initFromAgreementHeader(AgreementHeader::find(_purchAgreementHeader.RecId));
agreementLineQuantityCommitment.initFromInventTable(InventTable::find(_tmpProductsToAdd.ItemId));
agreementLineQuantityCommitment.CommitedQuantity = _tmpProductsToAdd.Quantity;
agreementLineQuantityCommitment.ProductUnitOfMeasure = InventTable::find(_tmpProductsToAdd.ItemId).purchUnitId();
agreementLineQuantityCommitment.ExpirationDate = today();
agreementLineQuantityCommitment.Category = EcoResProductCategory::findRetailCategoryByItem(_tmpProductsToAdd.ItemId);
agreementLineQuantityCommitment.ItemId = _tmpProductsToAdd.ItemId;
agreementLineQuantityCommitment.setInventDimId(_tmpProductsToAdd.InventDim);
agreementLineQuantityCommitment.Agreement = _purchAgreementHeader.RecId;
agreementLineQuantityCommitment.insert();
Still unable to find where the problem.
Is there any other table involved.
Where you are creating this code...in the form do u have any menu item to import the data...if it is like that then you have to refresh the Listpage datasource...
DeleteOtherwise I can see everything is fine in the table fields.
Hi Krishna Reddy,
DeleteIm facing with the same as above issue. Did that problem resolved? Please help!
Thank in advance!
Code below will do the "trick"
DeleteagreementLineQuantityCommitment.clear();
agreementLineQuantityCommitment.initValue();
agreementLineQuantityCommitment.initFromAgreementHeader(agreementHeader);
agreementLineQuantityCommitment.initFromInventTable(InventTable::find(itemId));
agreementLineQuantityCommitment.CommitedQuantity = agreementQty;
agreementLineQuantityCommitment.PricePerUnit = agreementPurchPrice;
agreementLineQuantityCommitment.ProductUnitOfMeasure = UnitOfMeasure::find(purchReqUnitOfMeasure).Symbol;
agreementLineQuantityCommitment.ExpirationDate = agreementExpirationDate;
agreementLineQuantityCommitment.Category = EcoResProductCategory::findRetailCategoryByItem(itemId);
agreementLineQuantityCommitment.ItemId = itemId;
agreementLineQuantityCommitment.setInventDimId(inventDim.inventDimId);
agreementLineQuantityCommitment.Agreement = agreementHeader.RecId;
agreementLineQuantityCommitment.InventDimDataAreaId = agreementLineQuantityCommitment.ItemDataAreaId;
agreementLineQuantityCommitment.insert();
Also... in order to create header code below might be used:
DeletetransferVendTable = VendTable::find(vendAccount);
agreementHeader.initValue();
agreementHeader.initFromAgreementClassification(agreementClassification);
agreementHeader.initFromVendTable(transferVendTable);
agreementHeader.PurchNumberSequence = NumberSeq::newGetNum(PurchParameters::numRefPurchAgreementId()).num();
agreementHeader.WorkflowStatus_PSN = PurchAgreementWorkflowStatus::Approved;
agreementHeader.AgreementState = AgreementState::Effective;
agreementHeader.insert();
purchAgreementHeaderDefault.initFromVendTable(transferVendTable, agreementHeader.VendAccount);
purchAgreementHeaderDefault.PurchaseAgreementHeader = agreementHeader.RecId;
purchAgreementHeaderDefault.insert();
agreementHeaderDefault.initFromVendTable(transferVendTable);
agreementHeaderDefault.AgreementHeader = agreementHeader.RecId;
agreementHeaderDefault.insert();
Cheers!
Adding Products to Purchase Agreement Lines like Purchase Orders Lines.
ReplyDeleteadded the code in a class RetailCreateLinesFromProductsToAdd
Refresh list page its showing correctly in ListPage and Data gets inserted agreementLine and agreementLineQuantityCommitment tables properly with agreement recid.
But still its not showing in Purch agreement form.
Warm Regards
Ramanan - Ramanan2k10@gmail.com
could you send me your XPO, I will import and Check the code....
ReplyDeletemail id:-krishna.dynamics@gmail.com
Hi Krishna,
ReplyDeleteArticle was really helpful in order to create products.
And I need a help on attaching prodcut, storage and tracking dimension group to the newly created product throuhg code.
Please could you provide the sample code if you have for the same.
Thanks,
Ambanna Yatnal
Hi Ambanna,
DeleteI have posted the Part 2 with all the functionality for creating the product.
you can see in the following post
http://krishhdax.blogspot.dk/2012/07/ax2012-import-items-from-csv-part-2.html
Regards,
krishna.
Hi,
ReplyDeleteI am using AX 2012 Data Migration Framework(Beta) for Products import. when I import the products from the demo files given with the framework installation, the imported items are getting released. My actual requirement is to import the products into product master only, they should not be shown in released products. How to take the field mapping or any other way to achieve this??
Thanks.
Hi Ashish,
DeleteYou have to map the fields respectively to the table fields and you have to update the Entity class for your functionality. you can customize that entity class for your functionality if your required.
If you remove mapping for standard entity I think this will validate before importing into the target, so you have to update the entity class for doing your custom import
Regards,
krishna.
Hi Krishana,
ReplyDeleteI need upload customer data from csv file using X++
please help me.
After I insert reqItemTable using X++ and open the table or form I get this error:
ReplyDeleteYou cannot specify inventory dimension 'Site' for item coverage settings. You must set all coverage planned dimensions before you can define minimum and maximum inventory.
Here's my code
Select forupdate ReqItemTable;
reqItemTable.clear();
reqItemTable.initValue();
reqItemTable.initFromInventTable(inventTable::find(newPartEntry.ItemId));
reqItemTable.ItemId = newPartEntry.ItemId;
reqItemTable.covRule = reqcovtype::MinMax;
reqItemTable.CovPeriod = 1;
reqItemTable.MinInventOnhand = newPartEntry.MinInventOnHand;
reqItemTable.MaxInventOnhand = newPartEntry.MaxInventOnHand;
// reqItemTable.reqGroupId
reqItemTable.CovInventDimId = '000001';
reqItemTable.insert();
Note inventDimId '000001' has only one dimension SiteId
Resolved: Discovered (InventTable).DimGroupId value was invalid. Once (InventTable).DimGroupId was corrected to a valid value the error disappeared and Item coverage (reqItemTable) is working. Thought I'd post this solution in case someone else has a similar issue.
DeleteHi. I get this error when trying to import a record from csv.
ReplyDeleteCannot create a record in (InventItemSetupSupplyType). The record already exists.
Is this cause I've uncommented the axInventTable.parmClassification together with axInventTable.parmIntegration & axInventTable.parmRevisionId
or because it's on a AX 2012 r2 system?
Thor