Autonumbering In Acumatica
Today I want to share with you how I implemented autonumbering feature in acumatica for page CA304000.
My task originally was the following: add autonumbering feature to the "Document Ref" field with following rules:
a. step of incrementing is 1
b. length of field should be six characters. For example 000001, 000002, ... , 000223, 001024, ..., and so on
First of all I want to state that my way of adding much simpler then "canonical" ( according to acumatica manuals ) way of adding autonumbering. If you wish to use standard way you should accomplish so many steps that I should admit that my brain wasn't able to boil them in one project.
Instead of this I used the following steps.
1. In the page CA304000 I found class, which provides data for the page. It looks like this:
2. Created extention of class in the following way:
{
3. Located method which returns list of records for the page CA304000, it was the method: CAAdjRecords.
4. According to rules of acumatica, if I want to modify behaviour of method CAAdjRecords I should implement method caadjrecords.
5.
{
6. Implemented method which digs in DB, and returns needed number in string format:
{
var maxNbr = 1;
foreach (var cAddjRec in PXSelect<CAAdj>.Select(Base, new byte[0]))
{
var extRefNbr = ((CAAdj) cAddjRec).ExtRefNbr;
int curNbr = 0;
if (int.TryParse(extRefNbr, out curNbr))
{
maxNbr = curNbr + 1;
}
}
var result = maxNbr.ToString(CultureInfo.InvariantCulture).PadLeft(defaultLength, '0');
return result;
}
7. Used GetExtRefNbr in the method caadjrecords in the following way:
{
var res = new List<CAAdj>();
var availableCashAccounts = GetAvailableCashAccounts();
foreach (
var doc in
PXSelect<CAAdj, Where<CAAdj.draft, Equal<False>>>.Select(Base, new byte[0]))
{
if (((CAAdj)doc).RefNbr.Contains("NEW"))
{
((CAAdj) doc).ExtRefNbr = GetExtRefNbr();
}
}
return res;
}
8. Enjoyed results:
the field Document Ref.: was inserted automatically.
4 Comments
Angie Osorno said
Hi,
It's me, again hahaha
I read your articule
I read your article but I get it ... in my case I have a custom screen that I want to generate the automatic numerical value, but I do not know how.
could you it teach me how you do?
docotor said
Describe a bit more what kind of autonumbering you need?
angie said
Hi,
I have selector that it have to search registers about your numbering
for example, how invoice screen it do...
I sent an email to you
docotor said
I can't say that I understood what you mean.