Skip to main content
Question

how to make SalespersonID equal Current user ID by default when SalespersonID is null


Forum|alt.badge.img

here’s what i’m trying to achieve. I want, when a new record in Sales orders is created, if the SalesPersonID is not filled, if it ends up null, It should, by default, be the same as the Current user’s ID. how can I achieve this? can someone provide the code or an example? and where would I put it?

3 replies

darylbowman
Captain II
Forum|alt.badge.img+13

Put this is a Graph Extension of SOOrderEntry:

protected virtual void _(Events.FieldDefaulting<SOLine, SOLine.salesPersonID> e, PXFieldDefaulting b)
{
    SOLine row = e.Row;
    if (row is null) return;

    // Execute regular defaulting logic first
    b?.Invoke(e.Cache, e.Args);

    // If the SalesPersonID is still null, default to the current user's SalesPersonID
    if (row.SalesPersonID == null)
    {
        SalesPerson currentSalesPerson = SelectFrom<SalesPerson>.
            InnerJoin<EPEmployee>.
                On<EPEmployee.FK.SalesPerson>.
            InnerJoin<Users>.
                On<EPEmployee.FK.User>.
            Where<Users.pKID.IsEqual<AccessInfo.userID.FromCurrent>>.View.Select(e.Cache.Graph);

        e.NewValue = currentSalesPerson?.SalesPersonID;
        e.Cancel = true;
    }
}

 


Forum|alt.badge.img

alot of graphs with soorderentry show up when i search or the graph. can you be specific with whcih one?


darylbowman
Captain II
Forum|alt.badge.img+13

PX.Objects.SO.SOOrderEntry 


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