Question

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

  • 25 March 2024
  • 3 replies
  • 41 views

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

Badge +11

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;
}
}

 

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

Badge +11

PX.Objects.SO.SOOrderEntry 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved