[REFERENCE] & [LASTVALUE] - Retrieving Historical User Data
By combining the [REFERENCE]
and [LASTVALUE]
functions, you can retrieve historical attribute values. A common application is to retrieve a user's previous manager and department details, which is useful for processes like sending email notifications during a position change. This guide also covers using the[IFEMPTYUSE]
function to provide a fallback value if historical data does not exist.
Syntaxes
[LASTVALUE; Attribute]
: Retrieves the most recent previous value of the specifiedAttribute
.[REFERENCE; AttributeToReturn; LookupAttribute; LookupValue; MatchValue]
: Looks up an object and returns a specified attribute from it.[IFEMPTYUSE; PrimaryValue; FallbackValue]
: Returns thePrimaryValue
if it is not empty; otherwise, it returns theFallbackValue
.
Use Cases
Retrieving a Previous Manager's Contact Information
To find the email address or display name of a user's most recent former manager, you can use [LASTVALUE; Manager]
as the value to look up.
To get the Previous Manager's Email:
CODE[REFERENCE;Email;UserId;1;[LASTVALUE;Manager]]
To get the Previous Manager's Name:
CODE[REFERENCE;DisplayName;UserId;1;[LASTVALUE;Manager]]
Providing a Fallback to the Current Manager
If a previous manager is not found, the expressions above will return an empty value. To provide the current manager's details as a fallback, wrap the expression in an[IFEMPTYUSE]
function.
Email (Fallback to Current Manager):
CODE[IFEMPTYUSE;[REFERENCE;Email;UserId;1;[LASTVALUE;Manager]];[REFERENCE;Email;UserId;1;[manager]]]
Name (Fallback to Current Manager):
CODE[IFEMPTYUSE;[REFERENCE;DisplayName;UserId;1;[LASTVALUE;Manager]];[REFERENCE;DisplayName;UserId;1;[manager]]]
Advanced Usage: Non-Exact Matching
The [REFERENCE]
function has an optional final parameter that determines if the lookup requires an exact match:
[REFERENCE;AttributeToReturn;LookupAttribute;LookupValue;MatchValue;IsExactMatch]
When the IsExactMatch
parameter is set to false
, the MatchValue
field supports wildcards (%
). This is useful for complex, position-specific lookups, such as when a manager is employed across multiple companies and may have more than one UserId
.