Skip to main content
Solved

issue with the field updated event


Forum|alt.badge.img

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.

Best answer by Naveen Boga

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

            }
        }
    }

 

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+10
  • Semi-Pro III
  • 229 replies
  • June 22, 2023

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


Forum|alt.badge.img

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.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • Answer
  • June 22, 2023

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

            }
        }
    }

 


Forum|alt.badge.img

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.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • June 22, 2023

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

 

.


Forum|alt.badge.img

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


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • June 22, 2023

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings