web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Production Journal Report as Finished and Register Inventory Throught X++

(0) ShareShare
ReportReport
Posted on by
Hi Expert,
 
I need to create a RaF journal -> Register Item (Batch + Location) -> Posting Journal via code (x++). However, when the register process (specifically the inventTransWMS_Register class) is run, an error occurs: “Cannot edit a record in Batches (InventBatch). The record has never been selected.” Here is my code:
public void createRAF()
{
    InventTable                         inventTable;
    BOSPlanningSlitterCombinationItem   combinationItem;
    ProdJournalCheckPostProd            journalCheckPost;
    ProdJournalTable                    prodJournalTable;
    LineNum                             lineNumCount = 1;
    int                                 batchCount = 1;
    InventDim                           inventDimRM = InventDim::find(slitterReportLine.InventDimIdRM);
    PmfProdCoBy                         coByLoc;

    prodJournalTable.clear();

    prodJournalTable.initValue();
    prodJournalTable.JournalType        = ProdJournalType::ReportFinished;
    prodJournalTable.NumOfLines = 1;
    prodJournalTable.JournalNameId      = ProdParametersDim::findDefault().ProdJournalNameId;
    prodJournalTable.Description        = "Auto create RAF from Slitter report " + slitterReportLine.SlitterReportId;
    prodJournalTable.ProdId             = prodTableCreated.ProdId;
    prodJournalTable.VoucherDraw        = JournalVoucherDraw::Post;
    prodJournalTable.VoucherSeqRecId    = NumberSequenceTable::find(ProdParameters::numRefProdJournalVoucherId().NumberSequenceId).RecId;
    
    prodJournalTable.insert();

    while select combinationItem
        where combinationItem.PlanningSlitterOrderId == slitterPlanningTable.PlanningSlitterOrderId
        join inventTable
        where inventTable.ItemId == combinationItem.ItemId
        join coByLoc
        where coByLoc.ItemId == inventTable.ItemId
        && coByLoc.ProdId == prodTableCreated.ProdId
    {
        ProdJournalProd prodJournalProd;

        prodJournalProd.clear();

        prodJournalProd.initValue();
        prodJournalProd.initFromProdTable(prodTableCreated);
        prodJournalProd.initFromProdJournalTable(prodJournalTable);
        prodJournalProd.pmfInitFromInventTable(inventTable);

        prodJournalProd.InventTransId       = coByLoc.InventTransId;
        prodJournalProd.LineNum             = lineNumCount;
        prodJournalProd.InventDimId         = prodTableCreated.InventDimId;
        prodJournalProd.TransDate           = slitterReportTable.EntryDate;
        prodJournalProd.QtyGood             = combinationItem.Qty * (inventTable.BOSWidthStrip / slitterPlanningTable.SlitterWidth);
        prodJournalProd.ProdFinished        = true;

        prodJournalProd.insert();

        for (int i = 1; i <= combinationItem.Qty; i++)
        {
            InventBatchId inventBatchIdCreate = strFmt("%1P%2", inventDimRM.inventBatchId, batchCount);
            InventBatch inventBatchFG = InventBatch::findOrCreate(inventBatchIdCreate, inventTable.ItemId);
            TmpInventTransWMS tmpInventTransWMS;
            InventTransWMS_Register inventTransWMS_Register = InventTransWMS_Register::newStandard(tmpInventTransWMS);
            InventTrans inventTrans = InventTrans::findTransId(prodJournalProd.InventTransId);
            InventDim inventDimFGBatch;

            inventDimFGBatch.clear();

            inventDimFGBatch.InventSiteId = inventDimFG.InventSiteId;
            inventDimFGBatch.InventLocationId = inventDimFG.InventLocationId;
            inventDimFGBatch.wMSLocationId = inventDimFG.wMSLocationId;
            inventDimFGBatch.inventBatchId = inventBatchFG.inventBatchId;

            inventDimFGBatch = InventDim::findOrCreate(inventDimFGBatch);

            tmpInventTransWMS.clear();
            tmpInventTransWMS.initFromInventTrans(inventTrans);
            tmpInventTransWMS.InventQty = inventTable.BOSWidthStrip / slitterPlanningTable.SlitterWidth;
            tmpInventTransWMS.InventDimId = inventDimFGBatch.inventDimId;

            inventTransWMS_Register.writeTmpInventTransWMS(
                tmpInventTransWMS, inventTrans, inventDimFGBatch
            );

            inventTransWMS_Register.updateInvent(prodJournalProd);

            batchCount++;
        }

        lineNumCount++;
    }

    journalCheckPost = ProdJournalCheckPostProd::newPostJournal(prodJournalTable.JournalId, false);
    journalCheckPost.run();
}
 
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 779 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 670 Super User 2025 Season 2

#3
CU05031448-0 Profile Picture

CU05031448-0 520

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans