通过按钮创建多个记录,但仅创建一个记录

问题描述 投票:0回答:1

我试图在按下按钮时创建多个记录并将其显示在网格中。这些记录是在按下按钮时创建的,但是仅创建和显示一个记录。在测试中,我确定仅创建将由该过程创建的最终记录。按下按钮时,我没有收到任何错误,但仍然只得到一条记录。

    public PXSelect<TestDocument> Documents; //View of Grid

    protected void CreateDocument(ARInvoice invoice, ARPayment payment)
    {
        TestDocument testDoc = new TestDocument();
        //Creating TestDocument
        testDoc.CustomerID = invoice.CustomerID;
        testDoc.InvoiceID = invoice.RefNbr;
        testDoc.PaymentID = payment.RefNbr;
        testDoc.InvoiceTotal = invoice.CuryLineTotal;
        testDoc.PaymentTotal = payment.CuryLineTotal;
        testDoc.InvoiceDate = invoice.DocDate;
        testDoc.PaymentDate = payment.DocDate;
        Documents.Insert(testDoc);
        Persist();
    }

    public PXAction<FilterTable> Preview;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Preview")]
    protected void preview()
    {
        foreach(PXResult<ARPayment> paymentResult in PXSelect<ARPayment, 
                Where<ARPayment.openDoc, Equal<True>>>.Select())
        {
                ARPayment payment = (ARPayment) paymentResult;

                //ARInvoices that are open and share CustomerID with the ARPayment
                foreach(PXResult<ARInvoice> invoiceResult in PXSelect<ARInvoice, Where<ARInvoice.customerID, 
                        Equal<Required<ARPayment.customerID>>, And<ARInvoice.openDoc,Equal<True>>>>
                        .Select(this, payment.CustomerID))
                {
                      ARInvoice invoice = (ARInvoice) invoiceResult;
                      CreateTransaction(invoice, payment);
                }
        }
    }

  public class TestDocument : IBqlTable
  {

    #region TransactionID
    public abstract class transactionID : PX.Data.BQL.BqlInt.Field<transactionID> { }
    [PXDBIdentity]
    public virtual Int32? TransactionID { get; set; }
    protected Int32? tranID;
    #endregion

    #region InvoiceID
    [PXDBString(15, IsUnicode = true, InputMask = "")]
    [PXUIField(DisplayName = "Invoice Ref. Nbr.")]
    public virtual string InvoiceRefNbr{ get; set; }
    public abstract class invoiceRefNbr: PX.Data.BQL.BqlString.Field<invoiceRefNbr> { }
    #endregion

    #region PaymentID
    [PXDBString(15, IsUnicode = true, InputMask = "")]
    [PXUIField(DisplayName = "Payment Ref. Nbr.")]
    public virtual string PaymentRefNbr{ get; set; }
    public abstract class paymentRefNbr: PX.Data.BQL.BqlString.Field<paymentRefNbr> { }
    #endregion

    #region CustomerID
    [PXDBInt()]
    [PXUIField(DisplayName = "CustomerID")]
    [PXSelector(typeof(Customer.bAccountID), DescriptionField = typeof(Customer.acctCD))]
    public virtual int? CustomerID{ get; set; }
    public abstract class customerID: PX.Data.BQL.BqlInt.Field<customerID> { }
    #endregion

    #region InvoiceDate
    [PXDBDate()]
    [PXUIField(DisplayName = "Invoice Date")]
    public virtual DateTime? InvoiceDate{ get; set; }
    public abstract class invoiceDate: PX.Data.BQL.BqlDateTime.Field<invoiceDate> { }
    #endregion

    #region PaymentDate
    [PXDBDate()]
    [PXUIField(DisplayName = "Payment Date")]
    public virtual DateTime? PaymentDate{ get; set; }
    public abstract class paymentDate: PX.Data.BQL.BqlDateTime.Field<paymentDate> { }
    #endregion

    #region InvoiceTotal
    [PXDBDecimal()]
    [PXUIField(DisplayName = "Invoice Total")]
    public virtual Decimal? InvoiceTotal{ get; set; }
    public abstract class invoiceTotal: PX.Data.BQL.BqlDecimal.Field<invoiceTotal> { }
    #endregion

    #region PaymentTotal
    [PXDBDecimal()]
    [PXUIField(DisplayName = "Payment Total")]
    public virtual Decimal? PaymentTotal{ get; set; }
    public abstract class paymentTotal: PX.Data.BQL.BqlDecimal.Field<paymentTotal> { }
    #endregion
}
acumatica
1个回答
0
投票

看来您的DAC缺少关键字段。

改为使用此属性定义TransactionID列:

[PXDBIdentity(IsKey = true)] 
© www.soinside.com 2019 - 2024. All rights reserved.