Solved

Trouble implementing ICurrentUserInformationProvider

  • 23 April 2024
  • 2 replies
  • 17 views

Userlevel 6
Badge +3

In my code below, the commented out loggedUserRow line uses an obsolete method.  I tried to implement the ICurrentUserInformationProvider to get the User ID.  When the code runs, the _currentUserInformationProvider variable is null.  I’m not sure what I need to do to instantiate the variable.  This is probably a c# thing.  I tried a bunch of things not shown here, but I couldn’t figure out how to implement that interface.  

        public ICurrentUserInformationProvider _currentUserInformationProvider { get; set; }

#region Events
protected virtual void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
{
if (e.Row == null)
{
return;
}

SOLine lineRow = (SOLine)e.Row;

//Users loggedUserRow = Users.PK.Find(this.Base, PXAccess.GetUserID());

System.Guid? u = _currentUserInformationProvider.GetUserId();

Users loggedUserRow = Users.PK.Find(this.Base, u.Value);

if (loggedUserRow != null)
{
UsersSSGExt loggedUserExtRow = this.Base.Caches[typeof(Users)].GetExtension<UsersSSGExt>(loggedUserRow);
if (loggedUserExtRow != null
&& loggedUserExtRow.UsrSSGDefaultWHS != null)
{
lineRow.SiteID = loggedUserExtRow.UsrSSGDefaultWHS;
}
}
}
#endregion

 

icon

Best answer by Django 23 April 2024, 19:23

View original

2 replies

Userlevel 7
Badge +5

Hi Joe,

  I did a search through the Acumatica code for ICurrentUserInformationProvider and everywhere it was declared, it had the [InjectDependency] attribute:

 [InjectDependency]

  private ICurrentUserInformationProvider _currentUserInformationProvider { get; set; }


If your declaration is missing that, could you add it and try again?

Userlevel 6
Badge +3

@Django Thanks for taking the time to dig that up.  It solved the error.

 

THANK YOU.

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