How to: Create Production Order through X++

1. Create a new Job.
2. Paste the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
static void _CreateProductionOrder(Args _args)
{
    ProdQty         qty     = 100;
    ItemId          item    = 'D0005';
 
    ProdTable       prodtable;
    InventTable     inventTable;
    InventDim       inventDim;
    ;
 
    // Initialize InventTable
    inventTable = inventTable::find(item);
 
    // Initialize the base values
    prodtable.initValue();
    prodtable.initFromInventTable(inventTable);
 
    prodtable.ItemId                = inventTable.ItemId;
    prodtable.DlvDate               = today();
    prodtable.QtySched              = qty;
    prodtable.RemainInventPhysical  = qty;
 
    // Initialize InventDim (Obrigatory)
    inventDim.initValue();
 
    // Set the active BOM and Route
    prodtable.BOMId = BOMVersion::findActive(prodtable.ItemId,
                                             prodtable.BOMDate,
                                             prodtable.QtySched,
                                             inventDim).BOMId;
 
    prodtable.RouteId = RouteVersion::findActive(prodtable.ItemId,
                                                 prodtable.BOMDate,
                                                 prodtable.QtySched,
                                                 inventDim).RouteId;
 
    // Initialize BOMVersion
    prodtable.initBOMVersion();
    // Initialize RouteVersion
    prodtable.initRouteVersion();
 
    //Use ProdTableType class to create the production order
    prodtable.type().insert();
 
    // Inform Production Order Id
    setPrefix( 'Production Order');
    setPrefix( 'Production Order Number');
    info(prodtable.ProdId);
}
3. Run the job. Check results.
2014-02-25 17_37_23-‪Log de Informações‬ (‎‪1‬)‎

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.