Skip to main content
Solved

How do I reload the SOOrderEntry Graph to be able to use newly created SegmentValue/Sub?


I did an SOOrderExtension, in which I overwrote the Persist method to add another method when saving, I call baseMethod() before and after my custom method.

This method creates a SegmentValue and an associated Sub. Now I want to save the SubID in the SalesSubID-Field of the SOLines of the Order. I get an Error that the Sub does not exist in the System. If I press Save again, everything will work just fine.

I tried clearing the Cache of SegmentValue and Sub, I tried clearing all the Caches. I tried using the Sub Graph to update SOLines fields.
Does anyone have an idea how I can fix this?

3 replies

Userlevel 7
Badge +5

Hi @larabierbaum

I tried the following override and I am able to set the SalesSubID. 

    public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
    {
        #region Event Handlers
        public delegate void PersistImplDelegate();
        [PXOverride]
        public void PersistImpl(PersistImplDelegate baseMethod)
        {
            foreach (SOLine currentLine in Base.Transactions.Select())
            {
                if (currentLine.SalesSubID == 500)
                    currentLine.SalesSubID = 499;
                else
                    currentLine.SalesSubID = 500;
                Base.Transactions.Update(currentLine);
            }
            baseMethod();
        }
        #endregion
    }

 

Are you trying to set the existing SubID? In some scenario, I think a new SubID can be created. Can you please share you code and steps to replicate the issue? 

As I described above, I am creating the SegmentValue and Sub in the overwrite as well. And then I can’t set the SalesSubID to the SubID of the newly created Sub.

int? saved_subid;
Sub subexists = SelectFrom<Sub>.Where<Sub.subCD.IsEqual<SOOrderExt.usrTextboxIntranetProjectNbr.FromCurrent>>.View.Select(Base);
 if (subexists == null)
            {
                SegmentValue segmentValueExists = SelectFrom<SegmentValue>.Where<SegmentValue.dimensionID.IsEqual<@P.AsString>.And<SegmentValue.segmentID.IsEqual<@P.AsInt>.And<SegmentValue.value.IsEqual<SOOrderExt.usrTextboxIntranetProjectNbr.FromCurrent>>>>.View.Select(Base, "SUBACCOUNT", 1);
                if (segmentValueExists == null)
                {
                    // creating SegmentValue
                    SegmentMaint segmentMaint = PXGraph.CreateInstance<SegmentMaint>();
                    SegmentValue svalue = new SegmentValue();
                    svalue.DimensionID = "SUBACCOUNT";
                    svalue.SegmentID = 1;
                    svalue.Value = orderext.UsrTextboxIntranetProjectNbr;
                    segmentMaint.Values.Insert(svalue);
                    segmentMaint.Actions.PressSave();
                }
                // creating Sub
                Customer customer = SelectFrom<Customer>.Where<Customer.bAccountID.IsEqual<SOOrder.customerID.FromCurrent>>.View.Select(Base);
                SubAccountMaint subGraph = PXGraph.CreateInstance<SubAccountMaint>();
                Sub sub = new Sub();
                sub.SubCD = orderext.UsrTextboxIntranetProjectNbr;
                sub.Description = customer.AcctName;
                sub = subGraph.SubRecords.Insert(sub);
                subGraph.Actions.PressSave();
                saved_subid = sub.SubID;
            }
            else
            {
                saved_subid = subexists.SubID;
            }

PXResultset<SOLine> orderlines = SelectFrom<SOLine>.Where<SOLine.orderNbr.IsEqual<SOOrder.orderNbr.FromCurrent>.And<SOLine.orderType.IsEqual<SOOrder.orderType.FromCurrent>>>.View.Select(Base);
foreach (SOLine orderline in orderlines)
            {
                orderline.SalesSubID = saved_subid;
                Base.Transactions.Update(orderline); // error
}

My code looks something like this. The error happens in the last line. Thank you

Userlevel 2
Badge

The problem is a check in the main graph for the existence of the SalesSubID. Which fails due to outdated caches (the sub was created in an instance of SegmentMaint and SubAccountMaint).
One solution is to use a new instance of SOOrderEntry to do the updates to SOLine as the new instance queries the database and gets the newly created SegmentValue and Sub.

Reply