acumaticapersist

Unable to update value for extension field in SOLine in Acumatica


I have a custom code running against SOOrder.RowPersisting. In that code, I run through the lines and need to update an extension field on a line.

I cannot get the change to persist to the DB.

Here is some pieces of the sample code:

    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {

        public PXSelect<SOLine,
            Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
            And<SOLine.orderType, Equal<Required<SOLine.orderType>>>>>
            SOLines;

        protected void _(Events.RowPersisting<SOOrder> e)
        {
            var sOOrder = e.Row;
            if (sOOrder == null) return;


            //Cycle through the items and expand any kits
            PXResultset<SOLine> lines = SOLines.Select(sOOrder.OrderNbr, sOOrder.OrderType);

            foreach (PXResult<SOLine> lineSet in lines)
            {
                SOLine line = (SOLine)lineSet;
                MAESxSOLine lineExt = PXCache<SOLine>.GetExtension<MAESxSOLine>(line);

                lineExt.UsrKitProcessed = true;
                SOLines.Cache.IsDirty = true;
                SOLines.Cache.Update(line);
                SOLines.Cache.Update(lineExt);
                SOLines.Cache.SetValueExt<MAESxSOLine.usrKitProcessed>(lineExt.UsrKitProcessed, true);
                        
                SOLines.Cache.Persist(PXDBOperation.Update);


As you can see, I have tried lots of different ways to set the extension field UserKitProcessed. It sets it in the cache, but doesn't seem to persist to the DB.

Any thoughts? I'm going a bit mad:)

Regards,

Shane


Solution

  • Instead of

    SOLines.Cache.SetValueExt<MAESxSOLine.usrKitProcessed>(lineExt.UsrKitProcessed, true);
    

    Use

    SOLines.Cache.SetValueExt<MAESxSOLine.usrKitProcessed>(line, true);
    

    SetValueExt needs the SOLine object, not the extension or the property. That must be messing things up.

    So the whole operation is :

    SOLines.Cache.SetValueExt<MAESxSOLine.usrKitProcessed>(line, true);
    SOLines.Cache.Update(line);
    SOLines.Cache.Persist(PXDBOperation.Update);