Solved

Linking a User account to an employee record by programming (API or C#)

  • 5 October 2022
  • 1 reply
  • 295 views

Userlevel 1

Is there a way to link an user account to an employee record?

I understand that I would need to set the UserID field on the employee's Contact record to the user's PKID value. 

From Slashdot this was one of the answers:


“In addition there is also Employee.UserID that you would want to set equal to the Users.PKID value. 
The virtual field is populated using that Contact.UserID value but in the RowUpdating handler Acumatica is updating both the Contact and Employee records when Users.ContactID is changed.”

 

Is there any more clarification on this? 

icon

Best answer by Brian Stevens 5 October 2022, 22:50

View original

1 reply

Userlevel 6
Badge +4

Yes.  In C#, just set Employee.UserID = to the Users.PKID, just as you stated.

In the following code, request an object for a custom DAC containing the AcctCD value on the EPEmployee record for which I want to link the User account.  Username contains the existing user (by login name) that I want to link to the employee.  This is significantly reduced to relevant code for your question, but I actually took this from a set of code where I create a user, the employee, the contact records for the employee, and link it all together.  However, this little bit should make the link you requested if your User and Employee exist.  Just replace the “request” references to your own variables/values.

EmployeeMaint graph = PXGraph.CreateInstance<EmployeeMaint>();
EPEmployee employee = graph.Employee.Search<EPEmployee.acctCD>(request.EPAcctCD);

AccessUsers graphUser = PXGraph.CreateInstance<AccessUsers>();
Users user = graphUser.UserList.Search<Users.username>(request.Username);

employee.UserID = user?.PKID;
graph.CurrentEmployee.Update(employee);

graph.Save.Press();

 

 

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