Help

Administration Guide

Custom Code for a Property Value (Get Format)

Updated 11 Nov 2026 7 min read

Reading several fields with SourceValues is available from Monosign v2026.11. In earlier versions the code can use only PropertyValue and SourceName.

A profile property is usually filled from one field of a directory, for example the directory field department fills the property Department. With Get Format you can change this value before Monosign stores it: write it in upper case, remove spaces, or build it from several fields of the same user, for example a display name made of the first name and the last name.

Where to find it

  1. In Management, open Directory > Profiles > Properties.

  2. Open the property and click Edit, or create a new property.

  3. Open the Advanced tab and set Get Format Type to Code.

  4. Next to Get Format, click Show Editor. The Code Editor (C#) window opens. The dark lines at the top list what the code can use and show three examples. They are help text and are not saved.

  5. Write the code, click Ok in the window, and click Save on the property.

The new value is written at the next synchronization of the user.

What the code can use

The code is C#. End it with return. The returned value is stored as the property value.

Name

What it holds

Example

PropertyValue

The value of the field that the property is mapped to.

PropertyValue.ToString().ToUpper()

SourceName

The name of the user source of the user.

SourceName

SourceValues["field"]

The value of another field of the same user record, as text. If the user has no such field, or the field is empty, the result is an empty text. Field names are not case-sensitive.

SourceValues["sn"]

SourceValues.Has("field")

true when the field has a value.

SourceValues.Has("initials")

Examples

One field: upper case

The property is mapped to sn. Lovelace is stored as LOVELACE.

return PropertyValue.ToString().ToUpper();

Several fields: first name and last name

The property is mapped to givenName. A user with the first name Ada and the last name Lovelace gets Ada Lovelace. A user without a last name gets Ada.

return (SourceValues["givenName"] + " " + SourceValues["sn"]).Trim();

Several fields: last name, first name

The result is Lovelace, Ada. When the last name is missing, only the first name is stored.

if (!SourceValues.Has("sn")) { return SourceValues["givenName"]; }
return SourceValues["sn"] + ", " + SourceValues["givenName"];

Add a field only when it has a value

The property is mapped to title. A user with the title Analyst and the department Research gets Analyst (Research). A user without a department gets Analyst. For Active Directory, add department to Additional Directory Properties of the source.

if (!SourceValues.Has("department")) { return SourceValues["title"]; }
return SourceValues["title"] + " (" + SourceValues["department"] + ")";

Several fields: display name and employee ID in square brackets

The property is mapped to displayName. A user with the display name Ada Lovelace and the employee ID 10042 gets Ada Lovelace [10042]. A user without an employee ID gets Ada Lovelace. For Active Directory, add employeeID to Additional Directory Properties of the source first. All steps are in the section Step by step below.

return SourceValues.Has("employeeID") ? SourceValues["displayName"] + " [" + SourceValues["employeeID"] + "]" : SourceValues["displayName"];

Several lines

var first = SourceValues["givenName"];
var last = SourceValues["sn"];
return (first + " " + last).Trim();

Good to know

  • The mapped field decides if the code runs. The code runs only when the field that the property is mapped to has a value. When that field is empty for a user, the property is left empty for this user, even if the other fields have values. Map the property to a field that every user has.

  • The value follows every field that the code reads. When the last name changes in the directory, the stored display name changes at the next synchronization, even if the mapped field did not change.

  • Which fields can be read depends on where the mapping is made:

    • Mapping on the property (Profile Property Details > Mappings, with a profile source): every field that the profile source returns for the user.

    • Mapping on the user source (Directory > Sources, the source, Settings, tab Mappings): the fields that the user source loads. For Active Directory these are, among others, displayName, givenName, sn, cn, name, mail, manager, sAMAccountName, userPrincipalName, distinguishedName, info, ou, uid, and every field that is used in a mapping of the source. Other fields, for example employeeID, department or title, are not loaded. Add them on the tab Attributes to Additional Directory Properties, separated by commas.

  • When the values are written. A value is written when the user is synchronized. A full synchronization writes the value for all users. On a large directory the first run can take several minutes. To start a full synchronization at the next run, turn on Full Sync for Next Run in the window Source Settings Save.

  • Showing the value to the user. Turn on Is Displayable on the Advanced tab of the property. The value is then shown on the profile page of the user, under the group of the property.

  • Do not save code that returns nothing. For example, code with only comments stores an empty value.

  • Code that you already use keeps working. Nothing changes for code that does not use SourceValues.

Step by step: display name and employee ID from Active Directory

The result is a property with a value like Ada Lovelace [10042].

Create the property

  1. Open Directory > Profiles > Properties and click Add New.

  2. On the Basic tab, fill in Title (for example Display Name with Employee ID) and Name (for example DisplayNameWithEmployeeId). Select Text as Type and select a Group. Group is required.

  3. On the Advanced tab, set Get Format Type to Code, click Show Editor, enter the code and click Ok:

    return SourceValues.Has("employeeID") ? SourceValues["displayName"] + " [" + SourceValues["employeeID"] + "]" : SourceValues["displayName"];
  4. To show the value on the profile page of the user, turn on Is Displayable.

  5. Click Save.

Map the property on the user source

  1. Open Directory > Sources, click the name of the Active Directory source and click Settings.

  2. On the tab Attributes, enter employeeID in Additional Directory Properties. Without this step the employee ID is not loaded, and the value contains only the display name.

  3. On the tab Mappings, enter displayName in Source Property Name and the name of the property (DisplayNameWithEmployeeId) in Profile Property Name. Click +.

  4. Click Save. In the window Source Settings Save, turn on Full Sync for Next Run to write the value for all users at the next run, and click Save.

Check the result

After the synchronization, open a user profile. A user with an employee ID shows a value like Ada Lovelace [10042]. A user without an employee ID shows Ada Lovelace.

If something is not as expected

What you see

Why

What to do

The property is empty for some users.

The mapped field is empty for these users in the directory.

Map the property to a field that every user has.

A part of the value is always missing.

The field name is not correct, or the user source does not load this field.

Check the field name. For Active Directory, add the field to Additional Directory Properties of the source.

The value did not change after you changed the code.

The value is written at the next synchronization.

Wait for the next synchronization of the source.

No value is written after you changed the code.

The code has an error.

Open the code again and compare it with the examples. The log of the Monosign service shows the error together with the name of the property or the user.

Nothing happens when you click Save on a new property.

Group is empty. The message Group is required. is shown on the Basic tab.

Open the Basic tab, select a Group and click Save again.

The value is stored, but the user does not see it on the profile page.

Is Displayable is off.

Turn on Is Displayable on the Advanced tab of the property.

Permanent link