Skip to main content

As shown in the above screenshot i have inserted a new field named Claim Percentage for the ARTran. After enter the values for the Quantity and Unit Price fields the Ext.Price should be calculated based on that two fields. Then If a value is entered to the Claim Percentage the Ext.Price should be updated as “Qty*UnitPrice*Claim Percenatge”. This is the my expected scenario.

In order to achieve this i have used a event handler in SOInvoiceEntry as shown in below.

public virtual void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
ARTran row = (ARTran)e.Row;

if (row != null && row.Qty != null && row.CuryUnitPrice != null)
{
ARTranExt tranExt = PXCache<ARTran>.GetExtension<ARTranExt>(row);

if (tranExt != null && tranExt.UsrClaimPercentage != null)
{
decimal claimExtPrice = (decimal)(row.Qty * row.CuryUnitPrice * (tranExt.UsrClaimPercentage / 100));

sender.SetValue<ARTran.curyExtPrice>(row, claimExtPrice);
}
}
}

This is aligned with my requirement. However, right after entering the values for the Quantity,Unit Price and Claim Percentage fields the Ext.Price is not calculated. As shown in the above screenshot when another new blank record is inserted by double-clicking, the Ext.Price is getting updated as “Qty*UnitPrice*Claim Percenatge”.

But I'm expecting to update the Ext.Price immediately right after entering the values. So can I know how to achieve this?     

  

Hi @malinthawarnakulasooriya08,

You can use the FieldUpdated event of the custom field like below,

		protected void ARTran_UsrClaimPercenatge_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

var row = (ARTran)e.Row;
if (row != null && row.Qty != null && row.CuryUnitPrice != null)
{
ARTranExt tranExt = PXCache<ARTran>.GetExtension<ARTranExt>(row);

if (tranExt != null && tranExt.UsrClaimPercenatge != null)
{
decimal claimExtPrice = (decimal)(row.Qty * row.CuryUnitPrice * (tranExt.UsrClaimPercenatge / 100));

cache.SetValue<ARTran.curyExtPrice>(row, claimExtPrice);
}
}
}

Also, set CommitChanges to True for the field, so each time user tabs out of the field, call to the server is made,

 

Feel free to post if you have any questions. Good Luck.!


Thank you @Vignesh Ponnusamy .It worked very well.


Reply