How to implement auto generating document number o

2019-07-12 19:44发布

I have a requirement to create a opportunity like screen and I do not know how to implement the auto generating the document number for newly created document

I am looking forward someone to help me on this issue.

The following steps I have used and I have attached the code for review. I am getting error while saving and not generating the number

  1. I have create a numbering sequence for Memo In document enter image description here

  2. I have created a DAC for Sequence number setup

    region MemoInOrderId

    public abstract class memoInOrderId : PX.Data.IBqlField
    {
    }
    protected string _MemoInOrderId;
    [PXDBString(10, IsUnicode = true)]
    [PXDefault("MEMOIN")]
    [PXSelector(typeof(Numbering.numberingID),
                 DescriptionField = typeof(Numbering.descr))]
    [PXUIField(DisplayName = "Memo In Order Nbr")]
    public virtual string MemoInOrderId
    {
        get
        {
            return this._MemoInOrderId;
        }
        set
        {
            this._MemoInOrderId = value;
        }
    }
    #endregion
    
  3. I have added Auto Generation Sequence number to MemoIn DAC

`

#region OrderNbr
    public abstract class orderNbr : PX.Data.IBqlField
    {
    }
    [PXDBString(10, IsUnicode = true, IsKey = true, InputMask = ">CCCCCCCCCCCCCCC")]
    [PXUIField(DisplayName = "Order Nbr", Visibility = PXUIVisibility.SelectorVisible)]
    [AutoNumber(typeof(MemoSetUp.memoInOrderId), typeof(AccessInfo.businessDate))]
    [PXSelector(typeof(MemoIN.orderNbr),
        new Type[]
            {
             typeof(MemoIN.orderNbr),
             typeof(MemoIN.orderDate),
             typeof(MemoIN.vendorId)
            })]
    public virtual string OrderNbr { get; set; }
    #endregion
  1. In the configuration Screen I have selected numbering sequence used for memo in documententer image description here

While saving the Memo In document I am getting the following error

enter image description here

I have noticed the Order number is not initialized to "NEW" and it is showing "SELECT"

I have gone through CASetup , CMSetup , ARSetup DAC code and not able to figure out the difference.

标签: acumatica
1条回答
淡お忘
2楼-- · 2019-07-12 20:17

If we want to use a numbering sequence it is very straight forward in Acumatica. You should have a setup/preferences field somewhere that defines which numbering sequence you will use for your document number field.

Here is an example of a setup field using a selector to pick a numbering sequence:

// Setup field indicating which numbering sequence to use.
public abstract class myNumberingID : PX.Data.IBqlField
{
}
protected String _MyNumberingID;
[PXDBString(10, IsUnicode = true)]
[PXSelector(typeof(Numbering.numberingID), DescriptionField = typeof(Numbering.descr))]
[PXUIField(DisplayName = "My Numbering Sequence")]
public virtual String MyNumberingID
{
    get
    {
        return this._MyNumberingID;
    }
    set
    {
        this._MyNumberingID = value;
    }
}

Next, in your document number field you will use the AutoNumberAttribute to define the field as a consumer of a numbering sequence. Below is an example of a number field using the defined number sequence configured in the setup table above (Assumes "MyNumberingID" exists in DAC/Table "MySetup").

// Field using the numbering sequence...
public abstract class myNumberField : PX.Data.IBqlField
{
}
protected String _MyNumberField;
[PXDBString(15, IsUnicode = true, IsKey = true, InputMask = ">CCCCCCCCCCCCCCC")]
[PXUIField(DisplayName = "My Number", Visibility = PXUIVisibility.SelectorVisible)]
[AutoNumber(typeof (MySetup.myNumberingID), typeof (AccessInfo.businessDate))]
[PXDefault]
public virtual String MyNumberField
{
    get
    {
        return this._MyNumberField;
    }
    set
    {
        this._MyNumberField = value;
    }
}

Edit: Make sure in the graph building the documents to include a PXSetup view to the setup table.

Now when you insert and persist a new record on the DAC that contains your number field, the next numbering sequence value will be used (unless the numbering sequence is configured for manual numbering then the user must provide a value).

For a more complex configuration when there are multiple numbering sequences used based on specific conditions/field values, you can look at PX.Objects.IN.INRegister.RefNbr for an example. Look at INDocType.Numbering and how it changes the numbering sequence based on INRegister.docType (shown below). Another example would be sales order order types related to the sales order document.

public class NumberingAttribute : AutoNumberAttribute
{
    public NumberingAttribute()
        : base(typeof(INRegister.docType), typeof(INRegister.tranDate),
            new string[] { Issue, Receipt, Transfer, Adjustment, Production, Change, Disassembly },
            new Type[] { typeof(INSetup.issueNumberingID), typeof(INSetup.receiptNumberingID), typeof(INSetup.receiptNumberingID), typeof(INSetup.adjustmentNumberingID), typeof(INSetup.kitAssemblyNumberingID), typeof(INSetup.kitAssemblyNumberingID), typeof(INSetup.kitAssemblyNumberingID) }) { ; }
}
查看更多
登录 后发表回答