So, I can’t do this, eh? That’s how I read the error.
I’m sure many of you are laughing at the idea of this code. I just want the next available PO number that is above number X but below the number in company configuration, so that this site can have its own PO number set.
Anyhow, I guess the only way to melt down the system is in C#? Yay.
Since this is on PO.Update, why not perform a check and if it fails the check, throw an exception?
That will prevent the PO.Update method from completing and will force the user to enter a “valid” number.
The next time they try to save, it will evaluate the condition again.
@Aaron_Moreng I might be misunderstanding what you mean, but I’m trying to generate the next number, not validate it.
Well, OK, I’m validating it, too, but it’s not from user input.
But AFAIK, each site cannot have its own sequence of PO numbers natively. You can manually enter a number lower than the starting number in company config, or use a BPM to do the same.
Like I said, that was my first attempt at LINQ code, so it may not be 100%. But it did work (as long as there was already one PO between 10,000 and 30,000)
When there isn’t, I think it the first part (from ... .MAX() returns a null, and it errors when trying to evaluate null + 1
I thought I could get even more clever, and do the plant check in that LINQ code, but the plant is not stored with the POHeader
may i ask why you want to add plant check, if each company has its own sequence range then,
var ttPOHeader_xRow = (from ttPOHeader_Row in ttPOHeader
where ttPOHeader_Row.Added()
select ttPOHeader_Row).FirstOrDefault();
if(ttPOHeader_xRow != null)
{
var NextPONum = (from x in Db.POHeader where x.Company == ttPOHeader_xRow.Company select x.PONum).Max()+1
//now you can assign NextPONum to ttPOHeader.PONum
// OR if you have that value stored in Company table then
var NextPONum = (from x in Db.Company where x.Company == ttPOHeader_xRow.Company select x.YourCompanyLastPONumUDField)+1
}
Edit:
you can call this value from the plant table - if you decide to have different PONum range per plant not company- using the same principle, i.e. comparing to the session PlantID to get your record in Db.Plant table.
var NextPONum = (from x in Db.Plant where x.Company == ttPOHeader_xRow.Company && x.Plant == Session.PlantID select x.YourPlantLastPONumUDField)+1