🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Logged in Person presentation
This page was created by Hans.karlsen on 2018-09-19. Last edited by Wikiadmin on 2026-07-29.

You can control how the logged-in user's SysUser is shown in the Turnkey main menu by defining the SysUser class's DefaultStringRepresentation; this is for modelers who want the menu to display a person's name or other user-related context instead of only the user name.

What the main menu displays

The main menu uses the string representation of the logged-in SysUser. By default, this is the user's UserName. Set DefaultStringRepresentation on the SysUser class when you want the displayed value to include information reached through the user's associations.

For example, if SysUser has an optional association to Person, and Person has an optional association to House, you can display:

  • The user name when no Person is connected.
  • The person's first and last name when a Person is connected.
  • The person's name followed by the house name when both Person and House are connected.

Configure the representation

  1. Open the model in MDriven Designer.
  2. Locate the SysUser class.
  3. Set the class's DefaultStringRepresentation to an OCL expression that returns the text you want shown in the main menu.
  4. Save the model and run the application.
  5. Log in with a user whose SysUser is connected to a Person, then verify the text in the main menu.

The representation is evaluated for the SysUser that is currently logged in. The current user is available through the application's SysSingleton; the login process sets its CurrentUser association for the session.

Example: show user name, person name, and house

Use the following expression as the SysUser DefaultStringRepresentation:

if self.Person->isempty then
  self.UserName
else
  self.Person.FirstName+' '+self.Person.LastName+
  if self.Person.House->isempty then
    ''
  else
    ' i hus '+self.Person.House.Name
  endif
endif

The expression checks optional associations before following them. This prevents the representation from trying to read Person properties when no Person is associated, or House properties when no House is associated.

SysUser data Displayed result
No Person is associated; UserName is alex@example.com alex@example.com
Person is associated with FirstName = Alex and LastName = Andersson; no House is associated Alex Andersson
Person is associated with Alex Andersson and House has Name = Oak House Alex Andersson i hus Oak House

How the expression works

  • self is the SysUser being presented.
  • self.Person->isempty tests whether the SysUser has no associated Person.
  • When Person is empty, the expression returns self.UserName.
  • When Person exists, the expression joins FirstName and LastName with a space.
  • The nested if adds i hus and the House name only when Person has a House.

Design guidance

Keep the DefaultStringRepresentation short and recognizable because it is used in the main menu. Include values that help the user identify the active account, such as a name and relevant organizational context.

Handle every optional association in the expression. In the example, Person and House can both be empty, so each is tested before its properties are used. If a value such as FirstName or LastName can be empty in your model, decide what text should be shown for that case and reflect it in the OCL expression.

DefaultStringRepresentation changes presentation only. It does not determine whether somebody is logged in and does not authorize access to actions or ViewModels. Use AccessGroups when you need to control visibility or availability based on the current user.

See also