Solved

A little Glitch to allow system pass the "PXErrorLevel.Error" and proceed to save and release doc?

  • 24 March 2023
  • 8 replies
  • 120 views

Userlevel 6
Badge +5

Hello,

      I don’t know it is my code issues or system framework issue.  Somehow, I encountered a case that the system can ignore the error on the screen and proceed to save and release document.

    My environment is Build 21.208.0032. So I don’t know this issue still exists in current version.

My need is to forbid SO invoice being saved/released if any line contains 0 qty.

I am using the below code mainly
 

protected void ARTran_RowSelected(PXCache cache, PXRowSelectedEventArgs e)

{

ARTran aRTran = (ARTran)e.Row;
if (aRTran != null)
{
using (new PXConnectionScope())
{
InventoryItem item = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, aRTran.InventoryID);
if (item != null) {

if (aRTran.Qty == 0)
{
cache.RaiseExceptionHandling<ARTran.qty>(aRTran,
aRTran.Qty, new PXSetPropertyException("Qty Can NOT be 0", PXErrorLevel.Error));

}
else
{
cache.RaiseExceptionHandling<ARTran.qty>(aRTran, null, null);
}

}

}

}

}

Normally this code works OK. But if the user operates in the below steps, the system can bypass error and proceed.

1, Save an invoice normally with all lines not equal to 0 qty.
2, Purposely change a line qty to 0, like 3rd line, and then move the mouse focus to another line, let’s say the 2nd line.
And then, click save.
At that time, the system allows the 0 qty to be saved.
And then,  click release. The invoice can be released with the red error alert on screen.
 

 


How can I enhance my code to fix the little hole? Please advise.​​​​​

icon

Best answer by Naveen Boga 24 March 2023, 07:45

View original

8 replies

Userlevel 7
Badge +17

@ray20 Can you please try below.

 

  protected virtual void ARTran_Qty_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated baseMethod)
        {
            baseMethod?.Invoke(sender, e);
            ARTran row = (ARTran)e.Row;
            if (row != null)
            {
                if (row.Qty == Decimal.Zero)
                {
                    sender.RaiseExceptionHandling<ARTran.qty>(row, row.Qty, new PXSetPropertyException("Quantity must be greater than 0", PXErrorLevel.Error));
                }
            }
        }

Userlevel 6
Badge +5

@Naveen Boga  Hello, thank you for your hands.
But unfortunately, your codes can not solve my issue, either.

What’s worse, the red alert is disappeared after the user click save.

I know, it is not good habit to put everything into “row selected” event. But if not, sometime, we might have some holes in our codes.  
 

 

Note, the Key hole step Is
“Purposely change a line qty to 0, like 3rd line, and then move the mouse focus to another line, let’s say the 2nd line.”
And then, click save.
If the user stays on the changing line, the save can not work.

Userlevel 7
Badge +17

Hi @ray20   Thanks for response.

Can you please confirm the below,

if any line item is having the ZERO qty, we should not allow to SAVE the document right? Please confirm.

If yes, you can use the below code.

 

 protected virtual void ARTran_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting baseMethod)
{
baseMethod?.Invoke(sender,e);
ARTran row = (ARTran)e.Row;
if (row != null)
{
if (row.Qty == Decimal.Zero)
{

sender.RaiseExceptionHandling<ARTran.qty>(row, row.Qty, new PXSetPropertyException("Quantity must be greater than 0", PXErrorLevel.Error));
}
}
}

 

Userlevel 6
Badge +5

@Naveen Boga  Awesome, this fixed the hold.  The codes just listened to you . You are master of codes. Thank you so much.

Userlevel 7
Badge +17

@ray20  You are most welcome. I’m glad that I helped on this customization.

 

Userlevel 6
Badge +5

@Naveen Boga  Hello, my friend, I am sorry to tell you, the solution we’ve made yesterday got a serious problem.  It would cause some shipments (with shipped qty=0 lines) can not be converted to invoices by using “prepare invoice” action.
But I do not quite understand, as I have tested, the shipped qty=0 lines would not actually be showed up on invoice. And also my codes in ARTran_RowSelected event gets no such issue.
So I am really surprised how are Shipment to Invoice generation and ARTran_RowPersisting working.
Are you getting what I am adressing at?  
1,  The shipped qty=0 lines are not showed up on the generated invoice. So I guess 0 lines are not persisting.
2,  However, the ARTran_RowPersisting event stops the shipment to invoice generation if shipments with shipped 0 lines. 
Weird.

No big issue. I have rolled back the codes and let system go.
Although there is a little hole in my code, but I assume the user would not change the qty  to  0, and then save purposely. And they would also not release the doc purposely with ignoring the obvious error msg on screen.
 

Userlevel 7
Badge +17

Hi @ray20  I just checked, if we have Shipped Qty as 0, system will NOT take such lines to the INVOICE document. Also, I don’t see any error on the Invoice preparation.

 

 

 

 

Userlevel 6
Badge +5

@Naveen Boga  Sorry for the late reply, I have a long weekend.  Yes, you are right, the shipped qty=0 lines would not appear on invoice. So that’s the strange things come from. Do you prepare invoice with the ARTran_RowPersisting event?
You did not meet the issue, might be we are not using the same version.  We still stay on Build 21.208.0032. Or The operations “prepare invoice” in batch on the processing screen not on shipment screen.
Anyway, I have commented the codes in (ARTran_RowPersisting) event. and the operations find it fine. Thank you for all your help.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved