Wednesday, April 23, 2014

Copy the existing route details using class through coding X++ in Ax 2012


static void BOMRouteCopyJob(Args _args)
{
    BOMRouteCopyJob      bOMRouteCopyJob;
    RouteVersion         routeVersion,newRouteVersion;
    RouteId              fromId,newId;
    InventSiteId         fromSiteId;
    EcoResItemConfigurationName             configId;
    RouteTable           routeTable;
    #define.item("1101")
    InventTable         inventTable= InventTable::find(#item);
    InventDim           inventDimVersion;
    ;

    Select routeversion where
        routeversion.ItemId == #item &&
        (routeversion.Approved == Noyes::Yes &&
        routeversion.Active == Noyes::Yes);

        fromId = routeversion.RouteId;
        configId = routeVersion.configId();
        fromSiteId = routeversion.inventSiteId();
       

    if (routeversion)
    {
        //Create a new route
        newId =  fromId + "/333" ;
        routeTable.RouteId = newId;
        routeTable.ItemGroupId = inventTable.itemGroupId();
        routeTable.insert();

       //Create a route version
        newRouteVersion.initFromRouteTable(routeTable);
        newrouteversion.initFromInventTable(inventTable);
        inventDimVersion.InventSiteId = fromSiteId;
        newRouteVersion.InventDimId = InventDim::findOrCreate(inventDimVersion).inventDimId;
        newrouteversion.insert();
    }

    //Copy the route details from another route  
    bOMRouteCopyJob = BOMRouteCopyJob::construct();
    bOMRouteCopyJob.parmFromRouteId(fromId);
    bOMRouteCopyJob.parmToRouteId(newId);
    bOMRouteCopyJob.checkBaseData();
    bOMRouteCopyJob.parmFromItemId(#item);
    bOMRouteCopyJob.parmToItemId(#item);
    bOMRouteCopyJob.parmToSiteId(fromSiteId);
    bOMRouteCopyJob.parmFromSiteId(fromSiteId);
    bOMRouteCopyJob.parmCopyRoute(true);
    bOMRouteCopyJob.run();
}

No comments:

Post a Comment