Skip to main content
Answer

Get Current user

  • March 5, 2024
  • 5 replies
  • 565 views

Forum|alt.badge.img

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

Best answer by Vignesh Ponnusamy

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,

5 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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,


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • March 5, 2024

I will try this thank you so much :)

 


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

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


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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;

 


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

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