Sample code used to import BOM lines from CSV
//Create the BomTable
protected void createBOMTable(container _conLine)
{
BOMId bomId;
BOMTable bomTable;
InventTable inventTable;
bomId = this.getLineValue(_conLine,
#BOMTable_BomId_ColumnNum);
bomTable = BOMTable::find(bomId,
true);
if(bomTable.RecId)
{
axBOMTable = AxBOMTable::newBOMTable(bomTable);
// Avoid update for better performance.
return;
}
else
{
axBOMTable = AxBOMTable::construct();
}
// BOMId
axBOMTable.parmBOMId(bomId);
// Name
axBOMTable.parmName(this.getLineValue(_conLine,
#BOMTable_Name_ColumnNum));
inventTable = InventTable::find(axBOMTable.parmBOMId());
// ItemGroupId
axBOMTable.parmItemGroupId(inventTable.itemGroupId());
// SiteId
axBOMTable.parmSiteId(inventTable.inventInventSiteId());
// Approver
AxBOMTable.parmApprover(gnDTDestAxBOM.parmApprover());
// Approved
axBOMTable.parmApproved(NoYes::Yes);
axBOMTable.save();
}
// create the BOM
protected void createBOM(container _conLine)
{
BOMId bomId;
ItemId itemId;
LineNum lineNum;
BOM bom;
bomId = axBOMTable.parmBOMId();
itemId = this.getLineValue(_conLine,
#BOM_ItemId_ColumnNum);
lineNum = this.getLineValue(_conLine,
#BOM_LineNum_ColumnNum);
select firstOnly forupdate bom
where bom.BOMId == bomId &&
bom.ItemId == itemId &&
bom.LineNum == lineNum;
if(bom.RecId)
{
axBOM = AxBOM::newBOM(bom);
// Avoid update for better performance.
return;
}
else
{
axBOM = AxBOM::construct();
}
// LineNum
axBOM.parmLineNum(lineNum);
// BOMType
axBOM.parmBOMType(this.getLineValue(_conLine,
#BOM_BOMType_ColumnNum));
// BOMConsump
axBOM.parmBOMConsump(this.getLineValue(_conLine,
#BOM_BOMConsump_ColumnNum));
// ItemId
axBOM.parmItemId(itemId);
// BOMQty
axBOM.parmBOMQty(this.getLineValue(_conLine,
#BOM_BOMQty_ColumnNum));
// RoundUpQty
axBOM.parmRoundUpQty(this.getLineValue(_conLine,
#BOM_RoundUpQty_ColumnNum));
// Position
axBOM.parmPosition(this.getLineValue(_conLine,
#BOM_Position_ColumnNum));
// UnitId
axBOM.parmUnitId(this.getLineValue(_conLine,
#BOM_UnitId_ColumnNum));
// BOMId
axBOM.parmBOMId(bomId);
// BOMQtySerie
axBOM.parmBOMQtySerie(1);
// ProdFlushingPrincip
axBOM.parmProdFlushingPrincip(ProdFlushingPrincipBOM::Blank);
axBOM.save();
}
// Create the BOM Version
protected void createBOMVersion(container _conLine)
{
ItemId itemId;
BOMId bomId;
BOMVersionActive active;
FromQty fromQty;
BOMVersion bomVersion;
itemId = this.getLineValue(_conLine,
#BOMVersion_ItemId_ColumnNum);
bomId = axBOMTable.parmBOMId();
active = NoYes::Yes;
fromQty = 1;
bomVersion = BOMVersion::find(itemId,
bomId,
active,
dateNull(),
dateNull(),
fromQty,
true);
if(bomVersion.RecId)
{
axBOMVersion = AxBOMVersion::newBOMVersion(bomVersion);
// Avoid update for better performance.
return;
}
else
{
axBOMVersion = AxBOMVersion::construct();
}
// ItemId
axBOMVersion.parmItemId(itemId);
axBOMVersion.parmInventDimId(bomVersion.InventDimId);
// BOMId
axBOMVersion.parmBOMId(bomId);
// Name
axBOMVersion.parmName(axBOMTable.parmName());
// Active
axBOMVersion.parmActive(active);
// FromQty
axBOMVersion.parmFromQty(fromQty);
// Approver
axBOMVersion.parmApprover(GNDTDestAxBOM.parmApprover());
// Approved
axBOMVersion.parmApproved(NoYes::Yes);
axBOMVersion.save();
}
public void run()
{
this.createBOMTable(container);
this.createBOM( container );
this.createBOMVersion( container );
}
Somehow the script doesen't work !
ReplyDeleteI have many errors!
Chris
I used the method getlineValue which included in other post you can get it from there.
ReplyDeletehttp://krishhdax.blogspot.dk/2012/05/ax2012-import-fixed-assets-table.html
Hi Krishna,
ReplyDeleteI go through above link, their is nothing about bom.