Skip to main content
Solved

Default values are being overwritten

  • January 6, 2025
  • 1 reply
  • 30 views

Forum|alt.badge.img

Hi Everyone,

I am currently facing an issue when inserting values into the database. The DAC has default values for certain fields, but whenever I insert new data, these default values are being overwritten, even though they should be retained automatically.

Could you please advise on the best approach to ensure that the default values are respected during the insertion process, and are not affected by the data being inserted?

Any assistance or guidance would be greatly appreciated.

this my code

 int linenum = EstimatePriceBreaks.Select().Count();

 AMEstimatePriceBreak PriceBreak = new AMEstimatePriceBreak
 {
     EstimateID = row.EstimateID,
     RevisionID = row.RevisionID,
     LineNbr = (linenum + 1),
     OrderQty = Total_Qty,
     UnitCost = Total_Price,
     CuryUnitCost = Total_Price,
     CuryExtCost = sum,
     ExtCost = sum
 };
 EstimatePriceBreaks.Insert(PriceBreak);
 Base.Actions.PressSave();
 Base.Caches.Clear();

Thank you in advance for your time and support.

Best answer by darylbowman

The issue arises as a result of trying to do too much at once. Instead of setting the values during inserting, insert the record, and then update the record with the values.

This happens because much of Acumatica’s defaulting logic runs as a result of other fields being updated. When these dependencies change during the inserting event, the system defaulting events will fire, causing your values to be disregarded.

AMEstimatePriceBreak PriceBreak = new AMEstimatePriceBreak
{
    EstimateID = row.EstimateID,
    RevisionID = row.RevisionID,
    LineNbr = (linenum + 1)
};
EstimatePriceBreaks.Insert(PriceBreak);
EstimatePriceBreaks.SetValueExt<AMEstimatePriceBreak.orderQty>(PriceBreak, Total_Qty);
// update other fields
EstimatePriceBreaks.Update(PriceBreak);
Base.Actions.PressSave();
Base.Caches.Clear();

 

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

1 reply

darylbowman
Captain II
Forum|alt.badge.img+13
  • 1698 replies
  • Answer
  • January 6, 2025

The issue arises as a result of trying to do too much at once. Instead of setting the values during inserting, insert the record, and then update the record with the values.

This happens because much of Acumatica’s defaulting logic runs as a result of other fields being updated. When these dependencies change during the inserting event, the system defaulting events will fire, causing your values to be disregarded.

AMEstimatePriceBreak PriceBreak = new AMEstimatePriceBreak
{
    EstimateID = row.EstimateID,
    RevisionID = row.RevisionID,
    LineNbr = (linenum + 1)
};
EstimatePriceBreaks.Insert(PriceBreak);
EstimatePriceBreaks.SetValueExt<AMEstimatePriceBreak.orderQty>(PriceBreak, Total_Qty);
// update other fields
EstimatePriceBreaks.Update(PriceBreak);
Base.Actions.PressSave();
Base.Caches.Clear();

 


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