Method Directive Condition question

,

None of those scenario’s are the issue. The part has no QOH and all I’m attempting to do is enable Track Lots, I can not accomplish it unless I disable the Method directive. My exception is the error that comes up, and when that method directive is disabled if you enable Track Lots it works without issue.

However when putting on a new PN it works as it should, doesn’t let you continue until one or the other is enabled.

Something is not right with how it’s setup. It’s as if that query is referencing the existing record before trying to process the update to the PN, where when adding a new PN there is no existing record so it has to reference what’s on the screen as the current data.

Try enabling it in your test environment UI. When I was learning DMT troubleshooting they always recommended trying the same process in the client.

I’ve abandoned testing it with the DMT, I was just explaining that was how I discovered the issue because I was removing QOH and updating with track lots to put QOH back in.

All of my further testing on existing PN’s and new entries have been on the client. You get the same error when running through the client as it does using the DMT.

I tested it on a single part in Part maintenance that had no QOH and it wont let me update it to track lots unless that directive is disabled. But add a new number with a -2 at the end all the same info, track lots checked and it will save that new PN.

I really feel that query is referencing the current DB data for existing records and not what’s on screen, aka what you’re trying to update it to.

Try this in pre on Part.Update:

var classIDs = new string[] { "SP", "FG", "FGF" };
foreach(var part in ds.Part.Where(o => o.Added() || o.Updated()))
{
  if(!part.TrackLots && !part.TrackSerialNum && classIDs.Contains(part.ClassID.ToUpper()))
  {
    var msg = $"Part class {part.ClassID} requires lot or serial number tracking.";
    throw new Ice.BLException(msg);
  }
}

Kevin, Thanks for the suggestion but that is above my level of understanding. Where would I put this? Is this an “execute custom code” or something else? I’m not well versed in writing code or BPM’s.

Yes, this BPM would consist of a single custom code block. The code essentially reads:

For each part that is being added or updated, if track lots is unchecked and track serial numbers is unchecked and the part class is in our list of part classes, then raise an error.

This should prevent you from adding a part that does not meet your criteria or changing an existing part so that it does not meet your criteria. It will also force you to fix existing parts that do not meet your criteria before you can change anything else on them.

2 Likes

Kevin, THANK YOU!

While you were replying I tried the single custom code block and it worked flawlessly! Prevents from adding new parts in those classes and makes me change, and allows me to change existing ones to now be tracked. I tested it on various scenarios including the one that had me stuck earlier… Open existing part that needs lot tracking, change anything and try to save and it yells at me, check off lot tracked and it actually saves it and works! beautiful!

Sadly I just finished fixing all of the existing parts that needed to be lot tracked and weren’t so in reality all this will ever do now is prevent someone from creating a class specific PN without proper tracking. But still I’m glad it works. :slight_smile:

1 Like

This is one of the many reasons I prefer custom code. It’s easier to share and discuss.

1 Like

you should also be able to shorten the code (and also reduce its execution time) by eliminating the “IF” statement in the middle of the loop… let the Linq Query do all the work. I often find code where a set of data is selected, and then inside a loop, additional if statements result in eliminating the need to loop… I reworked it here:

foreach(var part in ds.Part.Where(o => 
    (o.Added() || o.Updated()) &&
    !o.TrackLots && 
    !o.TrackSerialNum && 
    { "SP", "FG", "FGF" }.Contains(o.ClassID)
    )) {
    throw new Ice.BLException($"Part class {part.ClassID} requires lot or serial number tracking.");
  }
1 Like

I’m not sure if declaring the array inline would result in reallocation on every iteration. But modern compilers are smart like that, and there should only be zero or one iterations anyway.

Can anyone help?
I have something like this setup:
Where I set a variable to ttCustomerRow.TerritoryID and have it setup so that it sends out an email to each sales rep letting them know that a new customer is added within their region. However when testing this, nothing fires. I have this setup as a Method Directive under Post-Processing. Any clue to what I may be doing wrong?