Skip to main content
Question

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

  • March 25, 2024
  • 3 replies
  • 112 views

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+15

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+15

PX.Objects.SO.SOOrderEntry