Sunday, March 2, 2014

X++ code to create Production Job Card Journal in AX 2012

static void ProductionJobCardJournal(Args _args)
{
    Struct struct = new Struct();
    DimensionDefault    DimensionDefault;
    container  ledgerDimensions;
    DimensionDynamicAccount     offsetDimensions;
    Args    args;
    container ledgerDimension;
    InventDim   inventDim;
    ProdJournalRoute    prodJOurnalRoute;
    AxProdJournalTable  header = new axProdJournalTable();
    AxProdJournalRoute  trans = new axProdJournalRoute();
    ProdRoute       prodRoute;
    ProdRouteJob    prodRouteJob;


    header.parmJournalNameId("job");
    header.save();



     while select ProdRouteJob where ProdRouteJob.ProdId == "PRD_00004667"
    {

    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.parmProdId("PRD_00004667");
    trans.parmJobId(prodRouteJob.JobId);
    trans.parmDefaultDimension(DimensionDefault);
    //inventDim.InventSiteId = "2";
    //inventDim.InventLocationId = "21";
    //inventDim = InventDim::findOrCreate(inventDim);
    //trans.parm(inventDim.inventDimId);


    trans.parmVoucher("test");
    trans.parmCategoryHoursId("sdssetup");
    trans.parmCategoryQtyId("sdsqty");
    trans.parmOprNum(ProdRouteJob.OprNum);
    trans.parmHourPrice(10);
    trans.parmHours(10);
    trans.parmQtyGood(20);
    //trans.parmQtyError(1);
    //trans.parmWorker(000457);
    trans.parmTransDate(today());
    trans.parmJobType(RouteJobType::Process);

    Trans.currentRecord().insert();
    trans.save();
    Trans.currentRecord().clear();
    }


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

   
}

No comments:

Post a Comment