
There are many cases when you need to know who the current user is in bpm’online. Whether this is in client-side code on a form, or in server-side code in a process or a configuration service.
Getting the Current User in Client-Side Code
The current user is stored in Terrasoft.SysValue as CURRENT_USER. This is a global static script which can be obtained at at at point (even just typing it into the console).
var user = Terrasoft.SysValue.CURRENT_USER; // this object has two properties var userId = user.value; // the user's ID var name = user.displayValue; // the user name
Note, this is the user’s ID & username from SysAdminUnit, not the user’s contact ID. If you need the user’s contact, you can get it using the following (this is usually what you really want is the user’s contact):
var userContactId = Terrasoft.SysValue.CURRENT_USER_CONTACT.value; // or the user's account, if needed var userAccountId = Terrasoft.SysValue.CURRENT_USER_ACCOUNT.value;
Obviously, the displayName containing the contact’s name value is available there as well.
Getting the Current User in Server-Side C# Code
If you need the current user in C# code, this is available in the UserConnection as CurrentUser. Getting the UserConnection can vary depending on where your C# code is.
In a Script Task of a Process:
var currentUser = UserConnection.CurrentUser; var userId = currentUser.Id; var userName = currentUser.Name; // or current user contact var contactId = currentUser.ContactId;
Or from a configuration service:
var appConnection = HttpContext.Current.Application["AppConnection"] as AppConnection; var currentUser = appConnection.SystemUserConnection.CurrentUser;
Note, that the object you’re returned from UserConnection.CurrentUser is of type SysUserInfo. The SysUserInfo is just a C# object (not an entity that you’ll see in the database or configuration), implemented in Terrasoft.Core.dll. It inherits from SysAdminUnit and adds five additional properties to the SysAdminUnit data, which are: TimeZone, PageRowsCount, Culture, ClientIP, and DateTimeFormatCode. Other than those five properties, you’ll have the properties from SysAdminUnit available in this object.
Subscribe To Our Newsletter
Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!
You have Successfully Subscribed!