Skip to main content
Solved

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

  • Jun 20, 2022 5:13 AM UTC
  • 16 replies
  • 523 views
  • Translate All

Forum|alt.badge.img+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);
                    
                    }
                }
            }
   


      
    }

Best answer by Naveen Boga

@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> { }
}

 

View original

16 replies

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 20, 2022 5:31 AM UTC

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. 

Translate

Forum|alt.badge.img+1

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

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 20, 2022 5:37 AM UTC

@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

Translate

Forum|alt.badge.img+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?

Translate

Forum|alt.badge.img
  • Freshman II
  • Jun 21, 2022 3:46 AM UTC

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.

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 21, 2022 4:43 AM UTC

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

Translate

Forum|alt.badge.img+1

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

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 21, 2022 5:35 AM UTC

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

         }

Translate

Forum|alt.badge.img+1

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

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 21, 2022 8:23 AM UTC

@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.

Translate

Forum|alt.badge.img+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.

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 21, 2022 10:23 AM UTC

@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?

 

 

 

Translate

Forum|alt.badge.img+1

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

 

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Answer
  • Jun 21, 2022 11:25 AM UTC

@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> { }
}

 

Translate

Forum|alt.badge.img+1

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

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Jun 22, 2022 6:58 AM UTC

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

Translate