Skip to main content
Question

How To find issue Cancel Invoice

  • 5 September 2023
  • 4 replies
  • 124 views

Forum|alt.badge.img

. Invoice To Cancel Invoice Action to show this error How To slove this error ?

public delegate void PersistDelegate();
        [PXOverride]
        public void Persist(Action del)
        {
            if (Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
            {
                if (Base.Document.Current != null)
                {
                    ARTran objARTran = Base.Transactions.Select().FirstTableItems.ToList().FirstOrDefault();
                    if (objARTran != null)
                    {
                        SOOrder objSOOrder = SOOrder.PK.Find(Base, objARTran.SOOrderType, objARTran.SOOrderNbr);
                        if (objSOOrder != null)
                        {
                            SOOrderExt soOrderExt = objSOOrder.GetExtension<SOOrderExt>();
                            ARInvoiceExt invoiceExt = Base.Document.Current.GetExtension<ARInvoiceExt>();

                            invoiceExt.UsrCommentQuote = soOrderExt.UsrCommentQuote;
                            invoiceExt.UsrIntComment = soOrderExt.UsrIntComment;
                            invoiceExt.UsrPOComment = soOrderExt.UsrPOComment;
                        }
                    }
                }
            }
            del();
        }

 

Tony Lanzer
Semi-Pro I
Forum|alt.badge.img+2

I would first look at the Trace to see if there is any more error info, or to view the call stack to help determine what line of code is throwing the error.  If you want to post that info, someone can try to help further.


Forum|alt.badge.img+10
  • Semi-Pro III
  • September 6, 2023

Hi @Rajginoya ,

Below Code includes a check to ensure that the Customer ID is not empty before invoking the Persist method:

public delegate void PersistDelegate();
[PXOverride]
public void Persist(Action del)
{
    if (Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
    {
        if (Base.Document.Current != null)
        {
            ARTran objARTran = Base.Transactions.Select().FirstTableItems.ToList().FirstOrDefault();
            if (objARTran != null)
            {
                SOOrder objSOOrder = SOOrder.PK.Find(Base, objARTran.SOOrderType, objARTran.SOOrderNbr);
                if (objSOOrder != null)
                {
                    SOOrderExt soOrderExt = objSOOrder.GetExtension<SOOrderExt>();
                    ARInvoiceExt invoiceExt = Base.Document.Current.GetExtension<ARInvoiceExt>();

                    // Check if Customer ID is not empty before copying data
                    if (!string.IsNullOrEmpty(objSOOrder.CustomerID))
                    {
                        invoiceExt.UsrCommentQuote = soOrderExt.UsrCommentQuote;
                        invoiceExt.UsrIntComment = soOrderExt.UsrIntComment;
                        invoiceExt.UsrPOComment = soOrderExt.UsrPOComment;
                    }
                    else
                    {
                        // Handle the case where Customer ID is empty, e.g., throw an exception or log an error.
                        // You may need to decide how to handle this situation based on your business logic.
                    }
                }
            }
        }
    }
    del();
}

Regards,

Sweta


Forum|alt.badge.img
  • Jr Varsity III
  • September 11, 2023
sweta68 wrote:

Hi @Rajginoya ,

Below Code includes a check to ensure that the Customer ID is not empty before invoking the Persist method:

public delegate void PersistDelegate();
[PXOverride]
public void Persist(Action del)
{
    if (Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
    {
        if (Base.Document.Current != null)
        {
            ARTran objARTran = Base.Transactions.Select().FirstTableItems.ToList().FirstOrDefault();
            if (objARTran != null)
            {
                SOOrder objSOOrder = SOOrder.PK.Find(Base, objARTran.SOOrderType, objARTran.SOOrderNbr);
                if (objSOOrder != null)
                {
                    SOOrderExt soOrderExt = objSOOrder.GetExtension<SOOrderExt>();
                    ARInvoiceExt invoiceExt = Base.Document.Current.GetExtension<ARInvoiceExt>();

                    // Check if Customer ID is not empty before copying data
                    if (!string.IsNullOrEmpty(objSOOrder.CustomerID))
                    {
                        invoiceExt.UsrCommentQuote = soOrderExt.UsrCommentQuote;
                        invoiceExt.UsrIntComment = soOrderExt.UsrIntComment;
                        invoiceExt.UsrPOComment = soOrderExt.UsrPOComment;
                    }
                    else
                    {
                        // Handle the case where Customer ID is empty, e.g., throw an exception or log an error.
                        // You may need to decide how to handle this situation based on your business logic.
                    }
                }
            }
        }
    }
    del();
}

Regards,

Sweta
 

Hii,@sweta68
Not Working this Code Changes


Keith Richardson
Varsity II
Forum|alt.badge.img+2

I would try doing it in a RowPersisting event handler

 


        public virtual void _(Events.RowPersisting<ARInvoice> e, PXRowPersisting del)
        {
            ARInvoice invoice = (ARInvoice)e.Row;
            if (invoice != null && e.Cache.GetStatus(invoice) == PXEntryStatus.Inserted)
            {
                ARTran objARTran = Base.Transactions.Select().TopFirst;
                if (objARTran != null)
                {
                    SOOrder objSOOrder = SOOrder.PK.Find(Base, objARTran.SOOrderType, objARTran.SOOrderNbr);
                    if (objSOOrder != null)
                    {
                        SOOrderExt soOrderExt = objSOOrder.GetExtension<SOOrderExt>();
                        ARInvoiceExt invoiceExt = invoice.GetExtension<ARInvoiceExt>();
                        //should update current object as its persisting
                        invoiceExt.UsrCommentQuote = soOrderExt.UsrCommentQuote;
                        invoiceExt.UsrIntComment = soOrderExt.UsrIntComment;
                        invoiceExt.UsrPOComment = soOrderExt.UsrPOComment;
                    }
                }
            }

            del?.Invoke(e.Cache, e.Args);
        }

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings