Solved

Get Current user

  • 5 March 2024
  • 5 replies
  • 100 views

Userlevel 1

Can you help me on how can I get the current user (username) then assign it to a variable?

icon

Best answer by Vignesh Ponnusamy 5 March 2024, 23:27

View original

5 replies

Userlevel 7
Badge +4

Hi @melvinc,

You can user InjectDependency attribute and declare ICurrentUserInformationProvider then using which you can get the username. Below is an example for reference,

	public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
#region Event Handlers
[InjectDependency]
private ICurrentUserInformationProvider _currentUserInformationProvider { get; set; }
protected void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected baseHandler)
{
var row = (SOOrder)e.Row;
bool flag = false;
var curUser = _currentUserInformationProvider.GetUserName();
baseHandler?.Invoke(cache, e);
}
#endregion
}

 

Hope that helps.! Good Luck,

Userlevel 1

I will try this thank you so much :)

 

Badge +11

@Vignesh Ponnusamy - Is this superior to grabbing from AccessInfo?

Userlevel 7
Badge +4

Hi @darylbowman,

I don’t think so, it just an alternate way to get the username. In fact, ICurrentUserInformationProvider is an interface which makes us need additional line of codes get the necessary information.

Thanks for bringing this up.

@melvinc,

Alternatively, you can also try something like below

var curUserName = Base.Accessinfo.UserName;

 

Badge +11

@melvinc - Were you able to use the solution from Vignesh? If so, can you mark it as the answer?

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