Sunday, March 2, 2014

X++ code to create production Picking List Journal in AX 2012

static void ProductionPickingListJournal(Args _args)
{

    AxProdJournalTable header = new AxProdJournalTable();
    AxProdJournalBOM   trans = new AxProdJournalBOM();
    Struct struct = new Struct();
    DimensionDefault    DimensionDefault;
    container  ledgerDimensions;
    DimensionDynamicAccount     offsetDimensions;
    Args    args;
    container ledgerDimension;
    InventDim   inventDim;
    ProdBOM     prodBom;

    //Journal
    header.parmJournalNameId("Pick");
    header.save();
    while select prodBom where prodBom.ProdId == "PRD_00005257"
    {

        trans.parmProdId("PRD_00005257");//prodjournaltype::Picklist);
        //select prodBom where prodBom

        struct = new Struct();
        struct.add('Department',"00000024");
        struct.add('costcenter', "OU_3566");

        ledgerDimension = conNull();
        ledgerDimension += struct.fields();
        ledgerDimension += struct.fieldName(1);
        ledgerDimension += struct.valueIndex(1);
        ledgerDimension += struct.fieldName(2);
        ledgerDimension += struct.valueIndex(2);

        DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
        trans.parmJournalId(header.prodJournalTable().JournalId);
        trans.parmDefaultDimension(DimensionDefault);
        trans.parmItemId(prodBom.ItemId);
        trans.parmBOMUnitId("ea");
        inventDim.InventSiteId = "2";
        inventDim.InventLocationId = "21";
        inventDim = InventDim::findOrCreate(inventDim);
        trans.parmInventDimId(inventDim.inventDimId);
        trans.parmInventTransId(prodBom.InventTransId);
        trans.parmTransDate(today());
        trans.currentRecord().insert();
        trans.save();
        trans.currentRecord().clear();
    }

    info(strFmt("Journal %1 created",  header.prodJournalTable().JournalId));

    args = new Args();
    args.record(prodJournalTable::find(header.prodJournalTable().Journalid ));

    new MenuFunction(MenuItemDisplayStr(prodJournalTable),MenuItemType::Display).run(args);
}

No comments:

Post a Comment