Create BOM Journal example via x++ AX 2012

 

static void createMovJournal(Args _args)
{
  InventJournalTable  journalTable;
  InventJournalTrans  journalTrans;
  JournalId           journalId;
  CustomReportFinishedConvertItem    convertItem;
  InventJournalCheckPost journalCheckPost = new InventJournalCheckPost();
  ;

  // Init JournalTable

  journalTable.clear();
  journalTable.initValue();
  journalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().BomJournalNameId));
  journalId = NumberSeq::newGetNum(InventParameters::numRefInventJournalId()).num();
  journalTable.JournalId = journalId;
  journalTable.insert();

  journalTrans.clear();
  journalTrans.initFromInventJournalTable(journalTable);
  journalTrans.initFromInventTable(InventTable::find(convertItem.ItemIdChild));
  journalTrans.InventDimId = convertItem.InventDimId;
  journalTrans.Qty = convertItem.Qty;
  journalTrans.PriceUnit        = InventTableModule::find(journalTrans.ItemId, ModuleInventPurchSales::Invent).pcsPrice();
  journalTrans.CostAmount       = journalTrans.Qty * journalTrans.PriceUnit;
  journalTrans.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
  journalTrans.TransDate = today();
  journalTrans.Voucher = NumberSeq::newGetNumFromId(journalTable.VoucherNumberSequenceTable).num();
  journalTrans.BOMLine = NoYes::No;
  journalTrans.insert();

  inventTransId    = journalTrans.InventTransId;

  journalTrans.clear();
  journalTrans.initFromInventJournalTable(journalTable);
  journalTrans.initFromInventTable(InventTable::find(convertItem.ItemId));
  journalTrans.InventDimId = convertItem.InventDimIdRAF;
  journalTrans.Qty = -1*convertItem.QtyConversion;
  journalTrans.PriceUnit        = InventTableModule::find(journalTrans.ItemId, ModuleInventPurchSales::Invent).pcsPrice();
  journalTrans.CostAmount       = journalTrans.Qty * journalTrans.PriceUnit;
  journalTrans.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
  journalTrans.TransDate  = today();
  journalTrans.Voucher = NumberSeq::newGetNumFromId(journalTable.VoucherNumberSequenceTable).num();
  journalTrans.BOMLine = NoYes::Yes;
  journalTrans.InventTransIdFather =  inventTransId;
  journalTrans.insert();
  //end edited by fanddy


  // Call the static method to post the journal
  if(InventJournalCheckPost::newPostJournal(journalTable).validate())
  InventJournalCheckPost::newPostJournal(journalTable).run();

}

source :

1.http://www.andesoft.net/creating-bom-journal-using-x-code-ax-2009-ax-2012/

2.http://learnax.blogspot.com/2010/01/x-code-to-create-and-post-inventory.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s