Skip to main content
Question

Custom Lot Numbering

  • 8 August 2024
  • 9 replies
  • 60 views

Hi, there are a few options for defining the format of a lot number but I need to try and extend the options. The screen shot below shows a date based setup. This leads to a lot number like 2408

In the INLotSerClass table on the database you can see the format, which is : {0:yy}{0:dd}

I want to add a new option called DayOfYear, there are a few challenges to getting this into the UI but if this worked I might end up with a format like {0:yy}{0:w} and this would provide a lot number like 24221

w isn’t a valid datetime formatting string so I would need to adjust the Acumatica code. 

In the Acumatica source code in class Attribute.cs I can see that GetNextNumber is how the format is translated into a value to create a lot number. The code is below.

public static string GetNextNumber(PXCache sender, INLotSerClass lsClass, ILotSerNumVal lotSerNum)
{
string numval = new string('0', GetNumberLength(lotSerNum));
return string.Format(lsClass.LotSerFormatStr, sender.Graph.Accessinfo.BusinessDate, numval).ToUpper();
}

However, because it is a static method I don’t think I can override it. Is this correct? 

Is there a way to replace it with my own method?

As anyone else tried to add new options to provide more flexible lot number creation?

Thank you

Hi @stephenward03 As shown below, you can also provide Custom Date Format for the Lot serial class. 

 


Hi @steburri33 Please find the below link for details on the formats. Hope this helps you.

https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

 


However, because it is a static method I don’t think I can override it. Is this correct? 

Correct.

Is there a way to replace it with my own method?

You could try this:

public class CustomSelectorAttribute : INLotSerialNbrAttribute
{
public static new string GetNextNumber(PXCache sender, INLotSerClass lsClass, ILotSerNumVal lotSerNum)
{
string numval = new string('0', GetNumberLength(lotSerNum));
return string.Format(lsClass.LotSerFormatStr, sender.Graph.Accessinfo.BusinessDate, numval).ToUpper();
}
}

This would require you to replace the dINLotSerialNbr] with dCustomSelector] on the fields you want to override though.


Thanks @darylbowman,
I was starting to think about ways to tackle this by using custom attributes to work around the existing INLotSerialNbr attribute but I’ve yet to try any code.

I don’t know if I can replace the whole INLotSerialNbr attribute as there is a lot of code in there and I cannot understand some of it. 

I was wondering whether there might be a way to let Acumatica apply the INLotSerialNbr attribute and then apply my own custom attribute which could either replace some of the INLotSerialNbr events, or perhaps the actions of INLotSerialNbr - removing the elements which have been applied and adding my own.

Does this sound like a plan which could work? Do you know if attributes are applied in the order they are defined?

@ChandraM Thanks for the link to standard MS date time strings, but formatting a date isn’t where the problem is.


I don’t know if I can replace the whole INLotSerialNbr attribute as there is a lot of code in there and I cannot understand some of it. 

I think you misunderstand. You don't need to replace the code. You need to replace the Attribute. Meaning that you can override all the code you want from the original attribute, but it won't have any effect unless you replace the Attribute on the field with the selector.


Hi @darylbowman, I understood, though perhaps my reply didn’t explain very well. 

I would replace the attribute but the INLotSerialNbr attribute does loads of work and I’ll need to keep the vast majority of this. If I replace the INLotSerialNbr attribute with my own custom attribute then I think I’d need to copy and maintain lots of code which I don’t understand in order to keep the LotSerialNo field working correctly. I only want to change one small method in the attribute so this feels like a lot of work. 

My beginning of an idea was to leave the INLotSerialNbr in place, but somehow add/append a custom attribute which would somehow reverse some of what the INLotSerialNbr attribute has done, or replace certain elements of it. I’m not sure exactly how, but it’s an idea. 


If I replace the INLotSerialNbr attribute with my own custom attribute then I think I’d need to copy and maintain lots of code which I don’t understand in order to keep the LotSerialNo field working correctly.

You shouldn’t, if your custom selector inherits the original INLotSerialNbrAttribute, which the code above does.


aha, now I understand. I will try this and see what happens. Watch this space


Hi @stephenward03 were you able to find a solution? Thank you!


Reply