Mark Van
Mark Van

Reputation: 281

Copy Route information to Works order route

I am trying to copy multiple lines from a Route, Table: Route to the Route of a Works Order, Table: ProdRoute

I am trying the following code, which is not working:

    static void CopyRoute(Args _args)
{

ProdRoute        prodRoute;
Route            route;
ProdTable        prodTable;
;



ttsBegin;


INSERT_RECORDSET prodRoute
    (
    OprNum,
    OprPriority,
    OprId,
    OprNumNext
    )
Select
    OprNum,
    OprPriority,
    OprId,
    OprNumNext
from
    route
join prodTable
where prodRoute.ProdId == prodTable.ProdId &&
prodTable.RouteId == route.RouteId;

ttsCommit;

    info("Copy finished!");
}

This is the route itself:

enter image description here

And I want to copy the data between the red lines into the route of the works order:

enter image description here

As you can see in my Job, which isn't working, I want to accomplish this by joining the ProdTable itself, based on the RouteId on the ProdTable, I want to copy the lines from Route (which matches the RouteId). Then fill this data into the ProdRoute table of the Works Order.

I am not sure what step to take so I can accomplish this.

Upvotes: 0

Views: 644

Answers (1)

FH-Inway
FH-Inway

Reputation: 5117

The data structures around routes is too complex to achieve what you want with a single insert_recordset statement. To get started, you should look into the data structures of route, specifically tables RouteTable, RouteVersion, Route and RouteOpr and how they relate to each other. The biggest eye opener for me was when I realized that the lines of a route are not kept in one table Route, but the data is distributed between tables Route and RouteOpr and that one RouteOpr record can relate to more than one Route record.

After you got a feel for the data structures, I recommend taking a look at class ProdUpdCostEstimation and its method createProdRoute, which shows one example how standard functionality creates a production route from a route.

Upvotes: 3

Related Questions