Generating sequential Lot #'s in UD field

Hello all,

I created a UD field on the RcvDtl table and would like to generate a sequential lot # for each receipt detail, as they are entered. We create lot #'s for all receipts, regardless of whether a part number exists in our system, which is why I’m steering away from using built in lot functionality. Any thoughts?

Thanks,

Alice

I do this, but with the actual lot #. We have a UD field at the company level and then increment by one each line receipt.

First thought is a pre-processing BPM on RcvDtl with a condition if this field is empty (or zero?). If so, query the existing table for the maximum value already existing, add one, and insert into this field.

Can you tell me how you go about incrementing?

1 Like

Which setter should I use to accomplish this? I am not familiar with the Query related setters.

OK, this is what I would do for this one. Naturally, I’d recommend you try it in a dev system if you want to give this a go, and see if it does what you want.

Create two integer variables.

Add two “Set Argument/Variable” widgets, one for each of the variables you’ve just created. In the expression part of one, put

(int?)(from row in ttRcvDtl select row.yourUDfield).Max() ?? 0

in the other

(int?)(from row in Db.RcvDtl select row.yourUDfield).Max() ?? 0

Then add another conditional to compare the two. You can either set one of the variables to the other if it’s greater, or directly set the field either way. To do that, use a “Set Field” widget, and use your UD field in the changed row with expression of the greater variable +1.

I feel like this should work great, but my ignorance in C# is about to shine through. Are you able identify how I’ve botched my syntax? My UD field is “Character2”

Edit (after trying for myself) Just checking - what version of Epicor is this? Are these E9 UD fields? We went live on E10 so I don’t have experience of those. My original unedited advice below in case it helps, though …

Having a field named Character2 nearly foxed me, because I’d expect it to be a string, but looking at your screenshot it does seem to be an integer. So I think your solution is in this post:

If this does sort it, you’ll need System.Int32 in place of System.Decimal, otherwise that seems to be the syntax required in some cases.

Thank you! I am trying this out in test enviro and will mess with the ttTables syntax. I appreciate all the help.:grinning:

did this .Max() function ever work for you on type int?

Yes, it works for us where we’ve used it. But many things, this included, do depend on Epicor version and related .NET installation and, annoyingly, some things work in some places in Epicor but not others.

I confess I’m not a LINQ guru by any means, though. I can only suggest searching for for LINQ max options because there are usually several options that will achieve the same thing. You might want to try putting an “orderby descending” in there, for example, and then using FirstOrDefault() instead of Max().