Update Production Order Status to Started via code X++ in AX 2012

Update Production Order Status to Started via code X++ in AX 2012

Scenario: We have a batch job that posts all unposted picking lists that were imported from an external file.
Problem: Picking list can only be posted for those production orders that are in Started state.
Solution: Before posting, set the production order status to started.

CODE:

static void setProdStatusStarted(Args _args)
{
    ProdUpdStartUp      prodUpdStartUp;
    ProdParmStartUp     prodParmStartUp;
    ProdParametersDim   prodParametersDim;
    ProdTable           prodTable;
    
    ProdId              prodId = "PROD-0001";
    
    prodTable = ProdTable::find(prodId);
    
    ttsBegin;
    prodParmStartUp.initValue();
    prodParmStartUp.initParmDefault();

    prodParametersDim = ProdParametersDim::find(prodTable.InventDimId);

    prodParmStartUp.initFromProdParametersDim(prodParametersDim);
    prodParmStartUp.ProdId = prodTable.ProdId;
    prodParmStartUp.PostNowBOM = NoYes::No;

    prodParmStartUp.insert();
    ttsCommit;

    prodUpdStartUp = ProdUpdStartUp::construct();
    prodUpdStartUp.parmParmBuffer(prodParmStartUp);
    prodUpdStartUp.run();
}
Advertisements