Friday, 22 November 2013

AX2012 R2 : X++ Code to create picking list journal for a production order

Hi Friends,
Below is the sample of X++ code which can be used to create a picking list journal for a production order.
The journal header table is ProdJournalTable and the lines are stored in ProdJournalBOM table.
The table are related on the basis of Journal Type and Journal ID. The relation is defined on ProdJournalBOM table as shown below:

If you take a closer look, the 0 element in Base Enum of journal type field is "Picking list"

So the header table for all the journal types of production orders is ProdJournalTable. The lines table differ and can be easily traced from the forms and relations.

For illustration purpose I have hard coded some values but in real time u can get these form your functions/parameters/maps/list etc. Also I have created only one line, in real time scenarios you can have a list/function/while loop to create the lines for multiple items.

The difference see from AX2009 is the way we initialize voucherSeqRecId field of the journal header as it now stores the RecId of the voucher number sequenceID.

There are more fields in the prodJournalBOM table but with the minimum fields I included in the job, journal can be created and posted. In case you have record of ProdBOM table available for which you want to create the journal line then the task becomes more easy as you can call initFromProdBOM() function of the prodJournalBOM table as it can initialize the following fields and we can eliminate these lines from our job:

If you want to quickly reuse the code, here it is:

static void samplePickingListJournal(Args _args)
    ProdJournalTable    prodJournalTable;
    ProdJournalBOM      prodJournalBOM;
    ProdTable           prodTable = prodTable::find("PO-001159");

    prodJournalTable.JournalType    = ProdJournalType::Picklist;
    prodJournalTable.JournalNameId  = 'pickJrnl';
    prodJournalTable.Description    = " Prod pick list journal";
    prodJournalTable.ProdId         = prodTable.ProdId;
    prodJournalTable.VoucherDraw    = JournalVoucherDraw::Post;
    prodJournalTable.VoucherSeqRecId = NumberSequenceTable::find(ProdParameters::numRefProdJournalVoucherId().NumberSequenceId).RecId;

    prodJournalBOM.JournalId        = prodJournalTable.JournalId;
    prodJournalBom.ProdId           = prodTable.ProdId;
    prodJournalBom.LineNum          = 1;
    prodJournalBom.InventDimId      = "DIMID-99876";
    prodJournalBom.TransDate        = systemDateGet();
    prodJournalBom.BOMUnitId        = "Pcs";
    prodJournalBom.BOMConsump       = 10;
    prodJournalBom.InventConsump    = 10;
    prodJournalTable.NumOfLines = 1;
    info(strFmt("Journal %1 created",prodJournalTable.JournalId));

Thanks for reading the blog.


  1. Thanks for the post! Your code worked for me on time :) Happing Daxing.

  2. Hi, this is great information. I do have a project that involves customizing the production picking process. We've added a new table/form to identify the production line and picking location to be used to execute the production order. What we would like to do is only pick from the designated picking location for that particular production line. Can you provide some insight? btw, I've used your example to create a form to add onto the production picking list with on-hand inventory from the production line picking location.