Solved

Update custom checkbox value in a rowUpdated event handler of PORecieptEntry graph


Userlevel 4
Badge +1

I want to update UsrSendPONotifications checkbox(which is in PO screen) to true when I update a row in corresponding PO Receipt.

This is the code that I tried & it is not working. So , UsrSendPONotifications checkbox remains false.

Any idea about this?

 

 

 

protected void POReceipt_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
    {
      
            var row = (POReceipt)e.Row;
            if (row == null) return;
            else
            {
                POReceiptLine receiptLine = new PXSelect<POReceiptLine, Where<POReceiptLine.receiptNbr, Equal<Required<POReceiptLine.receiptNbr>>>>(Base).Select(row.ReceiptNbr);
                if(receiptLine == null) return;  
                else
                {
                    POOrder poOrder = new PXSelect<POOrder, Where<POOrder.orderType, Equal<Required<POOrder.orderType>>, And<POOrder.orderNbr, Equal<Required<POOrder.orderNbr>>>>>(Base).Select(receiptLine.POType, receiptLine.PONbr);
                    if(poOrder == null) return;
                    else
                    {
                        POOrderExt poExt = poOrder.GetExtension<POOrderExt>();
                        poExt.UsrSendPONotifications = true;
                        cache.SetValueExt<POOrderExt.usrSendPONotifications>(poOrder,poExt.UsrSendPONotifications);
                    
                    }
                }
            }
   


      
    }

icon

Best answer by Naveen Boga 21 June 2022, 13:25

View original

16 replies

Userlevel 7
Badge +17

Hi, @charithalakshan49  After creating the Purchase Receipt and Purchase Order will be in OPEN status and the system will not allows us to update the values.

As a first step, you need to enable the field from the workflow Automation steps when the PO is OPEN status and then try to update the field from the PORECEIPT. 

Userlevel 4
Badge +1

Hi, @Naveen Boga Thanks for the response. Can you please tell me how to enable the field from the workflow Automation steps?

Userlevel 7
Badge +17

@charithalakshan49  Can you please refer below article and let me know if you have queries.

https://asiablog.acumatica.com/2021/10/enable-customization-fields-when-document-is-completed.html

Userlevel 4
Badge +1

@Naveen Boga I code like this in the POOrderEntry_Extension class in rowselected event and in workflows I uncheck the disabled checkbox from the workflows open state. But the result is same. UsrSendPONotifications checkbox still remains as false.


            Base.Document.Cache.AllowUpdate = true;
            Base.Transactions.Cache.AllowUpdate = true;
            Base.CurrentDocument.Cache.AllowUpdate = true;
            PXUIFieldAttribute.SetEnabled<POOrderExt.usrSendPONotifications>(cache, row, true);

 

Any idea about this? what did I do wrong?

Userlevel 2
Badge

For Header Part Use the following Code : 

protected void POOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            var row = (POOrder)e.Row;
            Base.Document.Cache.AllowUpdate = true;

            PXUIFieldAttribute.SetEnabled<POOrderExt.usrSalesOrderNbr>(cache, row, true);
        

        }

 

For Detail Part Use the following Code : 

 

protected void POLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {

            var row = (POLine)e.Row;
            POOrder order = Base.Document.Current;

            if (order == null || row == null || Base.IsExport) return;

            if (order.Status == POOrderStatus.Open ||
                order.Status == POOrderStatus.Completed ||
                order.Status == POOrderStatus.Closed)
            {
                Base.Document.Cache.AllowUpdate = true;
                Base.Transactions.Cache.AllowUpdate = true;
                PXUIFieldAttribute.SetEnabled<POLineExt.usrXTermStart>(cache, row, true);
              
               PXUIFieldAttribute.SetEnabled<POLine.dRTermEndDate>(cache, row, true);
            }


        }

 

Along with the above code you have to enable the fields in Workflow Automation step as well.

Userlevel 7
Badge +17

Hi @charithalakshan49  Are you able to enable the field at screen when PO is in OPEN status? 

Userlevel 4
Badge +1

Hi , @Naveen Boga yes, I enabled the field in OPEN status. But the issue is still there.

Userlevel 7
Badge +17

@charithalakshan49   Since you are updating the field from Purchase Receipt to Purchase Order.

Please write the logic in the Persist() method in the PuchaseReceiptEntry graph extension instead RowUpdated event.

 

    public delegate void PersistDelegate();
        [PXOverride]
        public void Persist(PersistDelegate del)
        {

              //logic here

           del();

         }

Userlevel 4
Badge +1

@Naveen Boga Then, How do I run the logic when a row is Updated in PO Reciept screen? 

Userlevel 7
Badge +17

@charithalakshan49  Can you please let me know, what data you are updating at the PO Receipt level, so that we can decide based on this.

Userlevel 4
Badge +1

@Naveen Boga I update the vendor reference no. from PO Receipt screen and I want to set UsrSendNotifications checkbox to true which is in PO screen header , once I updated vendor reference from related PO receipt.

Userlevel 7
Badge +17

@charithalakshan49  I have a bit of confusion in the requirement, that when you update the value in the PO Receipt Line and it needs to be updated with a flag in the PO Order level instead line?

If you have multiple lines in the PO Receipt screen, for the first line you updated the Vendor Ref, and for another line you have NOT updated. What needs to be done in the case?

 

 

 

Userlevel 4
Badge +1

@Naveen Boga  Vender ref. number is not located in the PO receipt line level. isn’t it? 

 

Userlevel 7
Badge +17

@charithalakshan49  Yes, this is available at the header level but NOT the line level.

Please find the code sample below. 


public class POReceiptEntryExt : PXGraphExtension<POReceiptEntry>
{

public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate del)
{

if (Base.Document.Current != null)
{
if (!string.IsNullOrEmpty(Base.Document.Current.InvoiceNbr))
{
POOrderEntry POGraph = PXGraph.CreateInstance<POOrderEntry>();



foreach (POReceiptLine line in Base.transactions.Select()) // A PO Receipt may have multiple POs, it would be better if you get the receipt lines by grouping with POType and PONbr.
{
POOrder objPOOrder = PXSelect<POOrder, Where<POOrder.orderType, Equal<Required<POOrder.orderType>>,
And<POOrder.orderNbr, Equal<Required<POOrder.orderNbr>>>>>.Select(Base, line.POType, line.PONbr);
if (objPOOrder != null)
{
POGraph.Document.Current = objPOOrder;
POOrderExt poExt = objPOOrder.GetExtension<POOrderExt>();
poExt.UsrSendPONotifications = true;
POGraph.Document.Cache.Update(objPOOrder);
POGraph.Save.Press();
}
}
}
}

del();
}
}

public class POOrderExt : PXCacheExtension<POOrder>
{
[PXDBBool]
[PXUIField(DisplayName = "Send Notification")]
public bool? UsrSendPONotifications { get; set; }
public abstract class usrSendPONotifications : PX.Data.BQL.BqlBool.Field<usrSendPONotifications> { }
}

 

Userlevel 4
Badge +1

@Naveen Boga  Thank you so much for being helpful. It worked!🙌

Userlevel 7
Badge +17

@charithalakshan49   Most welcome :) Thanks for sharing the update.

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