3

In Numbering Sequences settings (CS201010), there is an option for manual numbering.

enter image description here

However, depending on the document type. There are instances where the reference number can be left blank. If it's blank, I'd want the auto numbering to kick in. Or something like call the NextNumber() function before saving the document. Is it possible ? How do I do that ?

At the moment, if I enforce the auto numbering. It doesn't allow me to type anything on the Reference number for example.

TIA

Rick
  • 1,301
  • 1
  • 16
  • 28

1 Answers1

0

There are two ways: easy and little bit more complicated. Easy one will be attach to FieldDefaulting, and inside of that event check if that field is empty then assign some value into it. Another way which better feet to Acumatica style is to implement your own AutoNumbering attribute and then apply that Autonumbering attribute to your DAC class. N.B. you can substitute Acumatica autonumbering attribute with yours with PXCacheExtension

below goes example of code with removing default autonumbering with implementing autonumbering via FieldDefaulting:

public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
{
    [PXDBString(15, InputMask = ">CCCCCCCCCCCCCCC", IsKey = true, IsUnicode = true)]
    [PXDefault]
    [PXUIField(DisplayName = "Reference Nbr.", TabOrder = 1, Visibility = PXUIVisibility.SelectorVisible)]
    //[ARInvoiceType.RefNbr(typeof(Search2<ARRegisterAlias.refNbr, InnerJoinSingleTable<ARInvoice, On<ARInvoice.docType, Equal<ARRegisterAlias.docType>, And<ARInvoice.refNbr, Equal<ARRegisterAlias.refNbr>>>, InnerJoinSingleTable<Customer, On<ARRegisterAlias.customerID, Equal<Customer.bAccountID>>>>, Where<ARRegisterAlias.docType, Equal<Optional<ARInvoice.docType>>, And2<Where<ARRegisterAlias.origModule, Equal<BatchModule.moduleAR>, Or<ARRegisterAlias.released, Equal<True>>>, And<Match<Customer, Current<AccessInfo.userName>>>>>, OrderBy<Desc<ARRegisterAlias.refNbr>>>), Filterable = true, IsPrimaryViewCompatible = true)]
    //[ARInvoiceType.Numbering] 
    //This is example of throwing away Acumatica autonumbering
    //[ARInvoiceNbr]
    [PXFieldDescription]
    protected void ARInvoice_RefNbr_Cacheattached()
    {

    }

    protected void ARInvoice_RefNbr_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        //here you can implement your way of initialization of this field

    }
}

Or with attribute you can try something like this:

//somewhere in your code
public class RickAutonumberingAttribute : ARInvoiceNbrAttribute
{
    //Here you'll need to play with implementation of your autonumbering
}

public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
{
    [PXDBString(15, InputMask = ">CCCCCCCCCCCCCCC", IsKey = true, IsUnicode = true)]
    [PXDefault]
    [PXUIField(DisplayName = "Reference Nbr.", TabOrder = 1, Visibility = PXUIVisibility.SelectorVisible)]
    [ARInvoiceType.RefNbr(typeof(Search2<ARRegisterAlias.refNbr, InnerJoinSingleTable<ARInvoice, On<ARInvoice.docType, Equal<ARRegisterAlias.docType>, And<ARInvoice.refNbr, Equal<ARRegisterAlias.refNbr>>>, InnerJoinSingleTable<Customer, On<ARRegisterAlias.customerID, Equal<Customer.bAccountID>>>>, Where<ARRegisterAlias.docType, Equal<Optional<ARInvoice.docType>>, And2<Where<ARRegisterAlias.origModule, Equal<BatchModule.moduleAR>, Or<ARRegisterAlias.released, Equal<True>>>, And<Match<Customer, Current<AccessInfo.userName>>>>>, OrderBy<Desc<ARRegisterAlias.refNbr>>>), Filterable = true, IsPrimaryViewCompatible = true)]
    //[ARInvoiceType.Numbering] 
    //This is example of throwing away Acumatica autonumbering
    [RickAutonumberingAttribute]
    [PXFieldDescription]
    protected void ARInvoice_RefNbr_Cacheattached()
    {
    }

}
Yuriy Zaletskyy
  • 4,983
  • 5
  • 34
  • 54
  • If there's an AutoNumbering attribute, it doesn't allow you to supply your own value. Its AutoNumbering all the way. The FieldDefaulting event is likely the way to go. However, how do I call the Invoice's AutoNumbering function manually in the FieldDefaulting event ? – Rick Jan 18 '18 at 04:24
  • @Rick to manually get the next auto number you can use AutoNumberAttribute.GetNextNumber. Note this will use up that number for each call regardless if you commit the returned number to your record. Not an issue for most but worth mentioning. – Brendan Jan 18 '18 at 16:33
  • @Yura Just did some testing and FieldDefaulting is not gonna do it as it fires right away as soon as I raise a new Invoice. RefNbr should be blank by default. Users can type their unique own values. Or leave it blank and let AutoNumber fill it in. So I'm guessing it will be on RowPersisting event ? Unfortunately, it only kicks in after successful validation. And RefNbr is not allowed to be blank hence RowPersisting is not fired. Just to re-iterate, I'm not after a new implementation of Invoce's AutoNumbering. Rather I'd want to define, when it needs to execute or not. Thanks ! – Rick Jan 22 '18 at 08:19