0

My problem is that we inserted some routeOpr with the following logic (embedded in a job, see below) and now the RouteOpr form shows all the routeOpr entries in the RouteOpr Form no matter which ressource was selected.

Can someone please explain what the "RouteOpr" form is supposed to to if it is called via

'Organisation administration' / 'Area page' -> select a Ressource and click on 'Applicable for' / 'Operations'

enter image description here enter image description here

With some debugging I already found out what the query for the form is, but I don't understand why the form isn't just showing the routeOpr entries for the specific ressource.

    RouteOpr                        routeOpr;
    WrkCtrRouteOprActivity          wrkCtrRouteOprActivity;
    WrkCtrActivity                  wrkCtrActivity;
    WrkCtrActivityRequirementSet    wrkCtrActivityRequirementSet;
    WrkCtrAbility                   wrkCtrAbility;
    WrkCtrActivityRequirementView   wrkCtrActivityRequirementView;

    changeCompany('someCompany')
    {
        WHILE SELECT routeOpr
            EXISTS JOIN wrkCtrRouteOprActivity
                WHERE routeOpr.RecId == wrkCtrRouteOprActivity.RouteOpr
                    EXISTS JOIN wrkCtrActivity
                        WHERE wrkCtrRouteOprActivity.Activity == wrkCtrActivity.RecId
                            EXISTS JOIN wrkCtrActivityRequirementSet
                                WHERE wrkCtrActivity.RecId == wrkCtrActivityRequirementSet.Activity
                                    NOTEXISTS JOIN wrkCtrActivityRequirementView
                                        WHERE wrkCtrActivityRequirementSet.RecId == wrkCtrActivityRequirementView.ActivityRequirementSet
                                            NOTEXISTS JOIN wrkCtrAbility
                                                WHERE wrkCtrActivityRequirementView.AbilityType == wrkCtrAbility.AbilityType
                                                   && wrkCtrActivityRequirementView.AbilityRecId == wrkCtrAbility.AbilityRecId
                                                   && (((wrkCtrAbility.LevelValue >= wrkCtrActivityRequirementView.MinimumLevelNeeded)))
                                                   && ((wrkCtrAbility.WrkCtrId == 'someWrkCtrId'))
                                                   && ((wrkCtrAbility.ValidFrom <= systemDateGet())
                                                   && ((wrkCtrAbility.ValidTo >= systemDateGet())))
                     {
                         Debug::printDebug(strFmt("%1 %2 %3", routeOpr.OprId, routeOpr.WrkCtrIdCost, routeOpr.ItemRelation));
                     }
    }

I think that I made some mistake and/or forgot something in my job, maybe someone can help me.

select forUpdate route;
select forUpdate routeOpr;
select forUpdate wrkCtrActivityResourceRequirement;
select forUpdate wrkCtrActivityRequirementSet;
select forUpdate wrkCtrActivityRequirement;


route.clear();
route.RouteId      = routeVersion.RouteId;
route.OprNum       = 10;
route.OprNumNext   = 0;
route.OprId        = oprId;
route.Level        = 1;
route.AccError     = 1.00;
route.insert();


routeOpr.clear();
routeOpr.ItemCode          = TableGroupAll::Table;
routeOpr.ItemRelation      = routeVersion.ItemId;
routeOpr.RouteCode         = RouteAll::Route;
routeOpr.RouteRelation     = routeVersion.RouteId;
routeOpr.OprId             = route.OprId;
routeOpr.ProcessPerQty     = 1.00;
routeOpr.FormulaFactor1    = 1.00;
routeOpr.WrkCtrIdCost      = ressource;
routeOpr.COL_UnitId        = "HMIN";
routeOpr.ProcessTime       = str2num(time);
routeOpr.RouteGroupId      = "SOLL=IST";
routeOpr.ToHours           = 0.0002;
routeOpr.insert();


wrkCtrActivityRequirementSet = routeOpr.activityRequirementSet();
wrkCtrActivityRequirementSet.selectForUpdate(true);
//wrkCtrActivityRequirementSet.LoadPercent = 100;
//wrkCtrActivityRequirementSet.Quantity    = 1;
wrkCtrActivityRequirementSet.update();

wrkCtrActivityRequirement.clear();
wrkCtrActivityRequirement.ActivityRequirementSet     = wrkCtrActivityRequirementSet.RecId;
wrkCtrActivityRequirement.RelationshipType           = WrkCtrActivityRequirementType::Resource;
wrkCtrActivityRequirement.UsedForJobScheduling       = NoYes::Yes;
wrkCtrActivityRequirement.UsedForOperationScheduling = NoYes::Yes;
wrkCtrActivityRequirement.insert();

wrkCtrActivityResourceRequirement.clear();
wrkCtrActivityResourceRequirement.setActivityRequirement(wrkCtrActivityRequirement.RecId);
wrkCtrActivityResourceRequirement.WrkCtrId = ressource;
wrkCtrActivityResourceRequirement.insert();
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
Thomas
  • 21
  • 4
  • Never seen this style of update/inserts before... `select forUpdate route;` looks unnecessary if you are going to _insert_ instead of _update_. `select forUpdate wrkCtrActivityResourceRequirement;` without filters will select _all_ rows. I am _guessing_ the related update() statement will only update the first row (fingers crossed it did not update all of them). Also, your inserts and updates are related, add a transaction (`ttsBegin;`, `ttsCommit;`) around them. – Sander Dec 11 '20 at 16:52
  • 2
    That's not a style, it's **WRONG**. Do not do it and DELETE that. What it is doing is selecting the entire table for update with a random single record in the buffer. Then his `.clear()` line is clearing all of the field data from that random record. After that he's replacing the fields with his own data, then the `insert()` command *might* actually save him. I'd have to do some testing with AX to see what actually happens because this should NOT be done. I *think* the insert would ignore all of that and create a new record and replace the variable with the single inserted buffer. – Alex Kwitny Dec 11 '20 at 16:57
  • Thank you both for your comments @AlexKwitny imagine the `select forUpdate` lines are deleted, would the job be correct?, I made a quick test and it looks like your assumption was correct, the insert just creates a new record, so for me it looks like the job works but I'm not 100% sure about the `wrkCtrActivityRequirementSet` which gets selected with `wrkCtrActivityRequirementSet = routeOpr.activityRequirementSet();` and then updated ... Maybe you could also tell me what the form is supposed to do? – Thomas Dec 14 '20 at 07:52
  • @Thomas - I don't remember everything about routes off hand and I don't have an environment with good data to repro, but this is pretty simple stuff if you have a debugger. That method just runs a simple query and returns the result. With the debugger, you can just step in and examine the query (or manually) examine it via regular code window. If it doesn't return a result, then it hasn't found the buffer. To say if your code is right/wrong is difficult because I don't have the data to check really. Debugger & table browser would be super easy to figure out though. – Alex Kwitny Dec 14 '20 at 20:19

1 Answers1

1

Apart from the incorrect job, the actual error was that I didn't set the value of the wrkCtrActivityResourceRequirement.ResourceDataAreaId field.

So i made a job which sets the field like this

wrkCtrActivityResourceRequirement.ResourceDataAreaId = curExt2dataareaid(tableNum(WrkCtrTable)); 

and now the correct entries are shown.

(I didn't notice the error because the field was set visible = No, so it was not shown in the table browser.)

Thomas
  • 21
  • 4