Saturday, 8 February 2014

AX2012 R2 CU7: X++ code to create and post route card journal for production order

Hi Friends,
The below code can be used to create and post route card journal in AX2012 R2 CU7 for a production order when we know the Production order number and the operation number.
I have assigned the costing resource defined on the route as the work center ID in this case.

static void createRouteCardJournalSample(Args _args)
{
    ProdJournalTable                      prodJournalTable;
    ProdJournalRoute                     prodJournalRoute;
    ProdRoute                               prodRoute;
    ProdId                                     prodId = 'PO000065';
    OprNum                                  oprNum = 10;
    RouteOprId                              routeOprId;
    ProdJournalCheckPostRoute     prodJournalCheckPostRoute;

    select prodRoute where prodRoute.ProdId == prodId
                        && prodRoute.OprNum == oprNum;

    prodJournalTable.clear();
    prodJournalTable.initValue();
    prodJournalTable.JournalType        = prodjournaltype::RouteCard;
    prodJournalTable.ProdId             = prodId;
    prodJournalTable.JournalNameId      = ProdParametersDim::findDefault().RouteJournalNameId;
    prodJournalTable.Description        =                                                  ProdJournalName::find(prodJournalTable.JournalNameId).Description;
    prodJournalTable.VoucherSeqRecId    = ProdJournalName::find(prodJournalTable.JournalNameId).VoucherSeqRecId;
    prodJournalTable.VoucherDraw        = journalVoucherDraw::Post;
    prodJournalTable.NumOfLines         = 1;
    prodJournalTable.insert();

    //Route card entry
    prodJournalRoute.clear();
    prodJournalRoute.JournalId               = prodJournalTable.journalId;
    prodJournalRoute.ProdId                   = prodId;
    prodJournalRoute.initValue();
    prodJournalRoute.OprNum                = oprNum;
    prodJournalRoute.OprId                    = prodRoute.OprId;
    prodJournalRoute.JobType                = RouteJobType::Process;
    prodJournalRoute.CategoryHoursId   = prodRoute.SetUpCategoryId;
    prodJournalRoute.CategoryQtyId      = prodRoute.ProcessCategoryId;
    prodJournalRoute.DefaultDimension  = prodRoute.DefaultDimension;
    prodJournalRoute.WrkCtrId              = prodRoute.WrkCtrIdCost;
    prodJournalRoute.QtyGood              = 2;
    prodJournalRoute.Hours                   = 1;
    prodJournalRoute.insert();
    info(prodJournalTable.JournalId);
   
    ProdJournalCheckPostRoute = ProdJournalCheckPostRoute::newPostJournal(prodJournalRoute.journalId,true);
    ProdJournalCheckPostRoute.run();
}


Thanks

4 comments:

  1. Wow, thank you so much. I've been digging for days. Still on 2009 but the code is almost identical, minus a couple field names.

    ReplyDelete
  2. Dear Priyanka Agarwal,

    I would like to reverse route card transaction.
    Could you please help me on my case?

    Thank you so much

    ReplyDelete
  3. now in 2021, thanks a lot Priyanka, your code helped me a lot .. This is simple great.. God Bless You..

    ReplyDelete
  4. My route card was created when Work Order started, and i want to posting all route card for all work order number which not ended , not for specific Work Order Number , how to define Work Order number for all Work Order.

    ReplyDelete