Suppose that you need to display the name of the current user. Let’s implement a virtual field that will display the current user name on the Customers form.
Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on Customers / Fields node, and press New Field.
![Creating a new field in Customers controller. Creating a new field in Customers controller.](/blog/2013/01/displaying-current-user-name-as-virtual/image02.png)
Use the following values:
Property | Value |
Name | CurrentUserName |
Type | String |
Length | 40 |
Allow null values. | true |
The value of this field is computed at run-time by SQL expression. | true |
SQL Formula | @BusinessRules_UserName
|
Label |
Current User |
Values of this field cannot be edited. |
true |
Press OK to save.
Let’s add this field to the edit form. Drop Customers / Fields / CurrentUserName (String(40)), read-only) node onto Customers / Views / editForm1 node. This will instantiate a CurrentUserName data field.
![Data field 'CurrentUserName' instantiated in view 'editForm1'. Data field 'CurrentUserName' instantiated in view 'editForm1'.](/blog/2013/01/displaying-current-user-name-as-virtual/image06.png)
On the toolbar, press Browse. Navigate to the Customers page and select a record. The Current User data field will display the user name at the bottom of the form.
!['Current User' displays the current user name at the bottom of the form. 'Current User' displays the current user name at the bottom of the form.](/blog/2013/01/displaying-current-user-name-as-virtual/image08.png)
Log out, and log in as user / user123%. The current user will change to reflect the current user account.
![The current user value has been updated. The current user value has been updated.](/blog/2013/01/displaying-current-user-name-as-virtual/image10.png)