Skip to main content
Question

How To find issue Cancel Invoice

  • Sep 5, 2023 6:57 PM UTC
  • 4 replies
  • 171 views
  • Translate All

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();
}

 

4 replies

Tony Lanzer
Captain II
Forum|alt.badge.img+3
  • Captain II
  • Sep 6, 2023 3:40 AM UTC

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.

Translate

Forum|alt.badge.img+9
  • Semi-Pro III
  • Sep 6, 2023 5:29 AM UTC

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

Translate

Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • Sep 11, 2023 2:20 PM UTC

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

Translate

Keith Richardson
Semi-Pro I
Forum|alt.badge.img+3

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);
}

 

Translate