Solved

issue with the field updated event

  • 22 June 2023
  • 7 replies
  • 86 views

Userlevel 3
Badge

Hi,

I have customized a new tab called ‘Discount’ to my custom data entry screen. There are two fields called Discount Amount and discount percentage in the grid as below.

When I changed a value of discount percentage, I want to set value to discount amount based on discountable amount just after the field updated. For that I used below code but it get executed when adding a new row.

protected void APProformaDiscount_DisctPercent_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (APProformaDiscount)e.Row;
APProforma item = APProformas.Current;

decimal? amount = (row.DiscountableAmt * row.DisctPercent) / 100;
//row.DisctAmt = amount;
cache.SetValue<APProformaDiscount.disctAmt>(row, amount);

}

Even I tried with cache.SetValueExt but it also didn’t work.

Note: this is custom graph

Can someone help me on this to find a solution please?

Thank you.

icon

Best answer by Naveen Boga 22 June 2023, 08:00

View original

7 replies

Userlevel 7
Badge +10

Hi @oshadarodrigo64 ,

I think you need to use below code snippet after setting the value.

 cache.Update(row);

to ensure that the field update is saved immediately.

Hope, it helps,

Regards,

Sweta

Userlevel 3
Badge

Hi @sweta68 ,

Thank you for your response. I tested your solution but the issue is still not solved and remained the same. Do you have any other idea on this? Thanks.

Userlevel 7
Badge +17

We should not use the Cache.Update(row) for sure, it leads to an infinite loop as it part of the same View.

I don’t see any issue with the code, have you added the COMMIT CHANGES = “true” for the DisctPercent field

Did minor changes to your code, just check please

 

    protected void APProformaDiscount_DisctPercent_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
APProformaDiscount row = (APProformaDiscount)e.Row;
if (row != null)
{
decimal? amount = 0m;
if (((row?.DiscountableAmt ?? 0m) * (row?.DisctPercent ?? 0m)) > 0m)
{
amount = (row.DiscountableAmt * row.DisctPercent) / 100;

cache.SetValueExt<APProformaDiscount.disctAmt>(row, amount);

}
}
}

 

Userlevel 3
Badge

Hi @Naveen Boga ,

Thank you for the response and I will test your solution and update you. btw, Is there any difference between SetValueExt and SetValue? I couldn’t find out any proper answer for this.

Userlevel 7
Badge +17

@oshadarodrigo64 Great Question. Hoping that the below details will help you to understand the difference.

 

SetValueExt: 

 When we use the SetValueExt, after assigning the value, it will internally invoke the below events.

  1. FieldUpdated
  2. FieldUpdating
  3. FieldVerifying

SetValue: 

 When we use the SetValue, it simply assigne the value, without invoking any events

 

Please find the screenshot for reference.

 

.

Userlevel 3
Badge

@Naveen Boga .

thank you for your explanation. Then it’s better to use setValueExt instead of setValue in these kind of scenarios right? however I applied your suggestion to the code and tested but seems like it leads to an infinite loop with setValueExt showing me an unhandled exception error but with setValue, there is no error but the field updated issue is not solved.

Userlevel 7
Badge +17

@oshadarodrigo64  Thanks for sharing the update.

The below code should work, if still not working, then it should be an issue with DAC fields / VIEW

 

protected void APProformaDiscount_DisctPercent_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
APProformaDiscount row = (APProformaDiscount)e.Row;
if (row != null)
{
decimal? amount = 0m;
if (((row?.DiscountableAmt ?? 0m) * (row?.DisctPercent ?? 0m)) > 0m)
{
amount = (row.DiscountableAmt * row.DisctPercent) / 100;

row.DisctAmt =amount;

}
}
}

 

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