
Hi all,
I want to create BOM version and BOM line through code and approve and activate it also, but through Job.
I Tried with direct insertion in table but it is showing some garbage value.
can any one please help me on this..
*This post is locked for comments
I have the same question (0)Even though this was asked quite a while ago, I had the same question. Unable to find the answer, I researched and found out how to do it myself.
In order to do what you are requesting, you have to first create an entry in the BOMTable and one or more entries in the BOM table. I had to pull these out of my class, so they are sloppy and a lot is missing (validation within the class to name one thing).
An example of setting the BOMTable:
private boolean setBOMTable()
{
boolean ret=true;
InventTable = InventTable::find("<The Relevant Item Number>", false);
//some validation here
if (ret)
{
if (!BOMTable)
BOMTable.initFromInventTable(inventTable);
BOMTable.BOMId = "<The BOM ID - perhaps a number sequence>";
BOMTable.Name = "<The name of the BOM>";
if (BOMTable.validateWrite())
{
BOMTable.write();
return true;
}
}
//error handling here
return false;
}
An example of setting the BOM Line
private boolean setBOM()
{
InventTable invent = InventTable::find("<the item on the bom line>", false);
boolean ret = true;
//validation here
if (ret)
{
if (!BOM)
BOM.initValue();
BOM.BOMType = BOMType::Item;
BOM.BOMConsump = BOMConsumpType::Variable;
BOM.ItemId = invent.ItemId;
BOM.BOMQty = 1.00; //the amount on the line
BOM.Calculation = NoYes::Yes;
BOM.BOMId = BOMTable.BOMId;
BOM.OprNum = 0;
BOM.UnitId = "EA"; //or any other UOM the item can handle
BOM.InventDimId = InventDim::findOrCreateBlank(); //for products, not masters
BOM.ScrapConst = 0.00; //amount of scrap
if (BOM.validateWrite())
{
BOM.write();
return true;
}
}
//error handling here
return false;
}
Version:
private boolean setBOMVersion()
{
InventTable InventTable = InventTable::find("Item to attach BOM to");
BOMVersion.initValue();
//some validation goes around here
BOMVersion.InventDimId = BlankDim;
BOMVersion.initFromInventTable(InventTable);
BOMVersion.initFromBOMTable(BOMTable);
try
{
if (BOMVersion.validateWrite())
{
this.tableRecord(BOMVersion);
return true;
}
}
catch
{
Global::exceptionTextFallThrough();
}
this.logError(strFmt("(%1) version failed write validation.", this.getExcelStringValue(InventTable.ItemId)));
return false;
}
Activation:
private boolean setBOMActive()
{
BOMApprove bomApprove = new BOMApprove();
RecId approver = HcmWorker::findByPersonnelNumber("A personnel number").RecId;
boolean ret=true;
try
{
bomApprove.init();
bomApprove.parmApprover(approver);
bomApprove.parmBOMId("The BOMID to approve");
bomApprove.run();
BOMVersion.selectForUpdate();
BOMVersion.Approved = true;
BOMVersion.Active = true;
BOMVersion.Approver = approver;
ttsBegin;
BOMVersion.write();
ttsCommit;
}
catch
{
this.logError(strFmt("(%1) approval failed.", this.getExcelStringValue(#ItemCode)));
ret=false;
}
return ret;
}
Hopefully this helps anyone else with this question.