Question Status

Verified
ChrisAX asked a question on 14 Mar 2014 6:01 AM

Hi I have 2 questions about BOM creation by code

1. do I have to create a BOMVersion (I think no but I am not sure)

2. how can I get the SiteID and Location to BOMTable and BOMLine

Currently I use the AxBom and AxBomLine Classes to create a new BOM (imported from Excel)

Reply
Verified Answer
Denis Macchinetti responded on 15 Mar 2014 4:19 AM

Hi Chris

Sorry, but is mandatory also BomVersion.

However, I have moved your code on a my AX 2012 Env.

The Site both for BomTable and Bom is fine.

I have added the BomVersion otherwise if you go through "Lines" from "Released Products" Form you aren't able to see the BomTable and Bom just created.

So, if with the code below the site is missing on BomTable table, check your  InventTable or debug the inventInventSiteId method from InventTable.

static void CreateBom(Args _args)

{

   InventTable     inventTable;

   BomTable        bomTable;

   ConfigGroup     cfgGroup;

   BOM             bom;

   BOMVersion      bomVersion;

   AxBOM           axBOM;

   axBOMTable      axBOMTable;

   AxBOMVersion    axBomVersion;

   InventDimId     inventDimId;    

   BOMId   bomid;

   ItemId  bomInventItem = "A";

   ItemId  itemid        = "SF286-S";

  ;

  bomId = bomInventItem + '_BOMImp_3';

  bomTable    =   BOMTable::find(bomId,true);

  cfgGroup = ConfigGroup::find(strFmt("%1VGrp",bomInventItem));

  if (cfgGroup.RecId ==0)

  {

      ttsBegin;

      cfgGroup.clear();

      cfgGroup.ConfigGroupId  = bomInventItem + 'VGrp';

      cfgGroup.Name           = strFmt("Variantengruppe für %1", bomInventItem);

      cfgGroup.insert();

      ttsCommit;

  }

  ///////////////  BOMTABLE

  if(bomTable.RecId)

  {

      //axBOMTable = AxBOMTable::newBOMTable(bomTable);

      // Avoid update for better performance.

      info(strFmt("Stückliste %1 bereits vorhanden", bomTable.BOMId));

  }

  else

  {

      axBOMTable = AxBOMTable::construct();

  }

  inventTable =   InventTable::find(bomInventItem);

  // BOMId

  axBOMTable.parmBOMId(bomId);

  // Name

  axBOMTable.parmName(inventTable.NameAlias);

  // ItemGroupId

  axBOMTable.parmItemGroupId(inventTable.itemGroupId());

  // SiteId

  axBOMTable.parmSiteId(inventTable.inventInventSiteId());

  // Approver

  //axBOMTable.parmApprover(HcmWorker::findByPersonnelNumber("000001").RecId);

  // Approved

  axBOMTable.parmApproved(NoYes::No);

  axBOMTable.save();

   bomTable = axBOMTable.bomTable();

   // BomVersion

   bomVersion = bomVersion::find(bomInventItem, bomId, true, systemDateGet() );

   If ( ! bomVersion )

   {

       axBomVersion = axBomVersion::construct();

       axBomVersion.parmItemId(bomInventItem);

       axBomVersion.parmBOMId(bomid);

       axBomVersion.parmName(BomId);

       axBomVersion.parmActive(true);

       axBomVersion.parmFromDate(systemDateGet());

       axBomVersion.parmToDate(systemDateGet());        

       axBomVersion.parmApproved(true);

       axBomVersion.parmApprover( HcmWorker::findByPersonnelNumber("000001").RecId );

       bomVersion = axBomVersion.bomVersion();

       bomVersion.initFromBOMTable( bomTable );

       bomVersion.initFromInventTable( inventTable );        

       axBomVersion.bomVersion(bomVersion);

       axBomVersion.save();

       bomVersion = axBomVersion.bomVersion();

   }

//////////////////

  select firstOnly forupdate bom

      where   bom.BOMId   ==  bomId   &&

              bom.ItemId  ==  itemid  &&

              bom.LineNum ==  1;

  if(bom.RecId)

  {

      axBOM = AxBOM::newBOM(bom);

      // Avoid update for better performance.

  }

  else

  {

      axBOM = AxBOM::construct();

  }

  inventTable = InventTable::find(itemid);

  if(!InventTable.RecId)

  {

      info(strFmt("Artikel %1 nicht vorhanden, Erstellung abgebrochen", itemId));

  }

  // LineNum

  axBOM.parmLineNum(1);

  // BOMType

  axBOM.parmBOMType(BOMType::Item);

  // BOMConsump

  axBOM.parmBOMConsump(BOMConsumpType::Variable);

  // ItemId

  axBOM.parmItemId(itemId);

  // BOMQty

  axBOM.parmBOMQty(2);

  // RoundUpQty

  axBOM.parmRoundUp(BOMRoundUp::No);

  // Position

  axBOM.parmPosition(strFmt("%1",1));

  // UnitId

  axBOM.parmUnitId(UnitOfMeasure::findBySymbol('pcs').Symbol);

  // BOMId

  axBOM.parmBOMId(bomId);

  // BOMQtySerie

  axBOM.parmBOMQtySerie(1);

  // ProdFlushingPrincip

  axBOM.parmProdFlushingPrincip(ProdFlushingPrincipBOM::Blank);

  if (EcoResProductDimensionGroupProduct::findByProduct(inventTable.Product).RecId)

  {

      axBOM.parmConfigGroupId(cfgGroup.ConfigGroupId);

  }

  bom =axBOM.boM();

  bom.initFromInventTable(inventTable);

  axBOM.boM(bom);

  //axBOM.parmInventDimId(inventTable::getInventDimId(itemId));

  axBOM.save();

}

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
Suggested Answer
Denis Macchinetti responded on 14 Mar 2014 7:03 AM

Hi

Bomversion is not require. Is enough the link with BomTable.

About the Inventory Dimensions, you can use "initFromInventTable" method of Bom Table where Site is already take from BomTable.

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
Suggested Answer
Denis Macchinetti responded on 14 Mar 2014 3:25 PM

Hi Chris

You can use AXBom class to initialize the Bom fields.

Then, write this code :

Bom        bom;

// Retrieve the Bom buffer

bom = AXBom.Bom();

// Set the InventDim fields, so Site from BomTable and location from InventTable

bom.initFromInventTable( InventTable::find( bom.itemId ) );

// Set the Bom buffer to the AxBom class

AxBom.Bom( bom );

That's it!

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
Suggested Answer
Denis Macchinetti responded on 14 Mar 2014 7:03 AM

Hi

Bomversion is not require. Is enough the link with BomTable.

About the Inventory Dimensions, you can use "initFromInventTable" method of Bom Table where Site is already take from BomTable.

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
ChrisAX responded on 14 Mar 2014 7:12 AM

as I wrote I use the AXBOM and AXBOMLINE classes to create the BOM. There is no possibility to call a initFromInventTable

Thanks & Regards

Chris

Reply
Denis Macchinetti responded on 14 Mar 2014 7:32 AM

Hi Chris

Try to check AxdBillsOfMaterials class, prepareForSave method

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
ChrisAX responded on 14 Mar 2014 2:31 PM

Hmm, maybe I am wrong but to me it looks like the data on the BOMTable has to be filled to get it on the Line....but how can I get the data to fill the BOMTable?

It looks like big chaos to me with that InventDim, Location and Site

BR

Chris

Reply
Suggested Answer
Denis Macchinetti responded on 14 Mar 2014 3:25 PM

Hi Chris

You can use AXBom class to initialize the Bom fields.

Then, write this code :

Bom        bom;

// Retrieve the Bom buffer

bom = AXBom.Bom();

// Set the InventDim fields, so Site from BomTable and location from InventTable

bom.initFromInventTable( InventTable::find( bom.itemId ) );

// Set the Bom buffer to the AxBom class

AxBom.Bom( bom );

That's it!

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
ChrisAX responded on 14 Mar 2014 3:38 PM

Basically I would say yes but for some reasons it doesn't work. SiteId and Location is still empty after creation

Reply
Denis Macchinetti responded on 14 Mar 2014 3:49 PM

Hi

Excuse me for the question, but when you call initFromInventTable method, the fields Itemid and BomId of Bom are already initialized?

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
ChrisAX responded on 15 Mar 2014 3:11 AM

yes they are. But not only the dimensions on the line are set, even Site on BOMTable not

Reply
ChrisAX responded on 15 Mar 2014 3:12 AM

protected boolean createBOMTable()

{

   InventTable     inventTable;

   ;

   bomId = bomInventItem + 'BOMImp';

   bomTable    =   BOMTable::find(bomId,true);

   cfgGroup = ConfigGroup::find(strFmt("%1VGrp",bomInventItem));

   if (cfgGroup.RecId ==0)

   {

       ttsBegin;

       cfgGroup.clear();

       cfgGroup.ConfigGroupId  = bomInventItem + 'VGrp';

       cfgGroup.Name           = strFmt("Variantengruppe für %1", bomInventItem);

       cfgGroup.insert();

       ttsCommit;

   }

   if(bomTable.RecId)

   {

       //axBOMTable = AxBOMTable::newBOMTable(bomTable);

       // Avoid update for better performance.

       info(strFmt("Stückliste %1 bereits vorhanden", bomTable.BOMId));

       return false;

   }

   else

   {

       axBOMTable = AxBOMTable::construct();

   }

   inventTable =   InventTable::find(bomInventItem);

   // BOMId

   axBOMTable.parmBOMId(bomId);

   // Name

   axBOMTable.parmName(inventTable.NameAlias);

   // ItemGroupId

   axBOMTable.parmItemGroupId(inventTable.itemGroupId());

   // SiteId

   axBOMTable.parmSiteId(inventTable.inventInventSiteId());

   // Approver

   //axBOMTable.parmApprover(HcmWorker::findByPersonnelNumber("000001").RecId);

   // Approved

   axBOMTable.parmApproved(NoYes::No);

   axBOMTable.save();

   return true;

}

protected boolean createBOMLine()

{

   AxBOM           axBOM;

   BOM             bom;

   InventTable     inventTable;

   InventDimId     inventDimId;

   ;

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

   }

   else

   {

       axBOM = AxBOM::construct();

   }

   inventTable = InventTable::find(itemId);

   if(!InventTable.RecId)

   {

       info(strFmt("Artikel %1 nicht vorhanden, Erstellung abgebrochen", itemId));

       return false;

   }

   // LineNum

   axBOM.parmLineNum(lineNum);

   // BOMType

   axBOM.parmBOMType(BOMType::Item);

   // BOMConsump

   axBOM.parmBOMConsump(BOMConsumpType::Variable);

   // ItemId

   axBOM.parmItemId(itemId);

   // BOMQty

   axBOM.parmBOMQty(pieces);

   // RoundUpQty

   axBOM.parmRoundUp(BOMRoundUp::No);

   // Position

   axBOM.parmPosition(strFmt("%1",lineNum));

   // UnitId

   axBOM.parmUnitId(UnitOfMeasure::findBySymbol('pcs').Symbol);

   // BOMId

   axBOM.parmBOMId(bomId);

   // BOMQtySerie

   axBOM.parmBOMQtySerie(1);

   // ProdFlushingPrincip

   axBOM.parmProdFlushingPrincip(ProdFlushingPrincipBOM::Blank);

   if (EcoResProductDimensionGroupProduct::findByProduct(inventTable.Product).RecId)

   {

       axBOM.parmConfigGroupId(cfgGroup.ConfigGroupId);

   }

   bom =axBOM.boM();

   bom.initFromInventTable(inventTable);

   axBOM.boM(bom);

   //axBOM.parmInventDimId(inventTable::getInventDimId(itemId));

   axBOM.save();

   return true;

}

Reply
Verified Answer
Denis Macchinetti responded on 15 Mar 2014 4:19 AM

Hi Chris

Sorry, but is mandatory also BomVersion.

However, I have moved your code on a my AX 2012 Env.

The Site both for BomTable and Bom is fine.

I have added the BomVersion otherwise if you go through "Lines" from "Released Products" Form you aren't able to see the BomTable and Bom just created.

So, if with the code below the site is missing on BomTable table, check your  InventTable or debug the inventInventSiteId method from InventTable.

static void CreateBom(Args _args)

{

   InventTable     inventTable;

   BomTable        bomTable;

   ConfigGroup     cfgGroup;

   BOM             bom;

   BOMVersion      bomVersion;

   AxBOM           axBOM;

   axBOMTable      axBOMTable;

   AxBOMVersion    axBomVersion;

   InventDimId     inventDimId;    

   BOMId   bomid;

   ItemId  bomInventItem = "A";

   ItemId  itemid        = "SF286-S";

  ;

  bomId = bomInventItem + '_BOMImp_3';

  bomTable    =   BOMTable::find(bomId,true);

  cfgGroup = ConfigGroup::find(strFmt("%1VGrp",bomInventItem));

  if (cfgGroup.RecId ==0)

  {

      ttsBegin;

      cfgGroup.clear();

      cfgGroup.ConfigGroupId  = bomInventItem + 'VGrp';

      cfgGroup.Name           = strFmt("Variantengruppe für %1", bomInventItem);

      cfgGroup.insert();

      ttsCommit;

  }

  ///////////////  BOMTABLE

  if(bomTable.RecId)

  {

      //axBOMTable = AxBOMTable::newBOMTable(bomTable);

      // Avoid update for better performance.

      info(strFmt("Stückliste %1 bereits vorhanden", bomTable.BOMId));

  }

  else

  {

      axBOMTable = AxBOMTable::construct();

  }

  inventTable =   InventTable::find(bomInventItem);

  // BOMId

  axBOMTable.parmBOMId(bomId);

  // Name

  axBOMTable.parmName(inventTable.NameAlias);

  // ItemGroupId

  axBOMTable.parmItemGroupId(inventTable.itemGroupId());

  // SiteId

  axBOMTable.parmSiteId(inventTable.inventInventSiteId());

  // Approver

  //axBOMTable.parmApprover(HcmWorker::findByPersonnelNumber("000001").RecId);

  // Approved

  axBOMTable.parmApproved(NoYes::No);

  axBOMTable.save();

   bomTable = axBOMTable.bomTable();

   // BomVersion

   bomVersion = bomVersion::find(bomInventItem, bomId, true, systemDateGet() );

   If ( ! bomVersion )

   {

       axBomVersion = axBomVersion::construct();

       axBomVersion.parmItemId(bomInventItem);

       axBomVersion.parmBOMId(bomid);

       axBomVersion.parmName(BomId);

       axBomVersion.parmActive(true);

       axBomVersion.parmFromDate(systemDateGet());

       axBomVersion.parmToDate(systemDateGet());        

       axBomVersion.parmApproved(true);

       axBomVersion.parmApprover( HcmWorker::findByPersonnelNumber("000001").RecId );

       bomVersion = axBomVersion.bomVersion();

       bomVersion.initFromBOMTable( bomTable );

       bomVersion.initFromInventTable( inventTable );        

       axBomVersion.bomVersion(bomVersion);

       axBomVersion.save();

       bomVersion = axBomVersion.bomVersion();

   }

//////////////////

  select firstOnly forupdate bom

      where   bom.BOMId   ==  bomId   &&

              bom.ItemId  ==  itemid  &&

              bom.LineNum ==  1;

  if(bom.RecId)

  {

      axBOM = AxBOM::newBOM(bom);

      // Avoid update for better performance.

  }

  else

  {

      axBOM = AxBOM::construct();

  }

  inventTable = InventTable::find(itemid);

  if(!InventTable.RecId)

  {

      info(strFmt("Artikel %1 nicht vorhanden, Erstellung abgebrochen", itemId));

  }

  // LineNum

  axBOM.parmLineNum(1);

  // BOMType

  axBOM.parmBOMType(BOMType::Item);

  // BOMConsump

  axBOM.parmBOMConsump(BOMConsumpType::Variable);

  // ItemId

  axBOM.parmItemId(itemId);

  // BOMQty

  axBOM.parmBOMQty(2);

  // RoundUpQty

  axBOM.parmRoundUp(BOMRoundUp::No);

  // Position

  axBOM.parmPosition(strFmt("%1",1));

  // UnitId

  axBOM.parmUnitId(UnitOfMeasure::findBySymbol('pcs').Symbol);

  // BOMId

  axBOM.parmBOMId(bomId);

  // BOMQtySerie

  axBOM.parmBOMQtySerie(1);

  // ProdFlushingPrincip

  axBOM.parmProdFlushingPrincip(ProdFlushingPrincipBOM::Blank);

  if (EcoResProductDimensionGroupProduct::findByProduct(inventTable.Product).RecId)

  {

      axBOM.parmConfigGroupId(cfgGroup.ConfigGroupId);

  }

  bom =axBOM.boM();

  bom.initFromInventTable(inventTable);

  axBOM.boM(bom);

  //axBOM.parmInventDimId(inventTable::getInventDimId(itemId));

  axBOM.save();

}

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply
ChrisR75 responded on 15 Mar 2014 11:36 AM

hmm this code Looks pretty similar to mine...but now it works.

Thanks a lot

Chris

Reply
Denis Macchinetti responded on 15 Mar 2014 11:44 AM

Hi Chris

There are two differences :

1- After AX... Save method, I have set the buffer with the insert record, like :

  axBOMTable.save();

  bomTable = axBOMTable.bomTable();

2- I have introduce BomVersion

Please, remember to tick the answer as verified.

Thanks & Regards

Denis Macchinetti

Senior Technical Architect

Reply