Expressions¶
When a Synchronisation Rule flows an attribute from one system to another, it often needs to do more than copy a value across unchanged. You might want to build an email address from a first and last name, force a username to lower case, decide whether an account should be enabled based on someone's employment status, or skip an object entirely unless it meets a condition. JIM's expression language is how you describe these transformations.
An expression is a short, readable formula that JIM evaluates during synchronisation to produce the value for a target attribute. If you have ever written a formula in a spreadsheet cell, this will feel familiar: you reference attributes much as a spreadsheet references cells, combine them with operators and functions, and JIM works out the result for each object as it is synchronised. No programming experience is required.
Where Expressions Fit¶
Expressions live inside Synchronisation Rules, in what is known as the Attribute Flow: the part of a rule that decides which value lands in each target attribute. Most flows are a direct mapping (copy cs["mail"] straight into mv["Email"]); you only reach for an expression when a plain copy is not enough.
Within a Synchronisation Rule, expressions are used in:
- Export attribute mappings
Transform Metaverse attributes before sending them to a Connected System. An export expression produces one value or several; one value written to a Multi-Valued attribute replaces every value the attribute holds (see Multi-valued attributes). - Import attribute mappings
Transform Connected System attributes before storing them in the Metaverse, and derive Metaverse attributes from other attributes of the same Metaverse Object. - Conditional logic
Choose different values based on conditions (e.g. enable or disable an account based on employee status). - Scoping filters
Compare a value reshaped from the object, in place of an attribute, to decide whether it is in scope for a Synchronisation Rule: see Comparing a computed value.
Expressions also decide what an Object Matching Rule compares, where an identifier differs in format between systems: see Matching on an expression.
To add or edit these mappings in the admin UI, see Synchronisation Rules. The rest of this guide focuses on the expressions themselves: the syntax, the built-in functions, and worked examples you can adapt.
Expressions are also used by example data generation templates to construct a generated attribute's value from other attributes on the same object, for example building an email address whose domain is derived from a generated company name. Only the mv accessor applies in that context (generation builds Metaverse Objects directly, so there is no Connected System Object), but the same syntax and functions described below apply. To try one before generating anything, test it with Test-JIMExampleDataExpression or the REST API's /api/v1/example-data/templates/{templateId}/test-expression: give the template attribute and sample values for the attributes it reads, and see the value it would be generated as.
Quick Examples¶
Before diving into the details, here are a few examples to give you a feel for how expressions work:
// Build an email address from first and last name
Lower(mv["First Name"]) + "." + Lower(mv["Last Name"]) + "@company.com"
// Enable or disable an account based on employee status
IIF(Eq(mv["Employee Status"], "Active"), 512, 514)
// Use the preferred name if available, otherwise fall back to the first name
Coalesce(mv["Preferred Name"], mv["First Name"])
Attribute Access¶
Expressions work with two sources of data:
mv
Attributes on the Metaverse Object (the central identity record).cs
Attributes on the Connected System Object (the external system record).
Access an attribute by putting its name in square brackets and quotes:
mv["Display Name"]
mv["Employee Status"]
mv["Department"]
cs["sAMAccountName"]
cs["userAccountControl"]
Which accessors mean something depends on where the expression runs. An export Attribute Flow reads mv; an import Attribute Flow reads cs. An import Attribute Flow can also read mv, the Metaverse Object it flows to, to derive one Metaverse attribute from others: see Deriving Metaverse attributes for the evaluation order, loops, and which synchronisation evaluates the flow. An Object Matching Rule's expression reads cs only, because the Metaverse Object is what the rule is looking for.
In the portal, wherever you type an expression (an Attribute Flow's Expression source, or a Generated Value's base expression), it is syntax highlighted as you type. Metaverse attribute references (mv["..."]) and Connected System attribute references (cs["..."]) each have a colour of their own, distinct from text and functions, so you can see at a glance which side of the Metaverse an expression reads; the Attribute Flow table colours them the same way.
Attribute names are matched case-insensitively, so mv["Department"], mv["department"], and mv["DEPARTMENT"] all refer to the same attribute. This applies to attribute names only; attribute values are compared case-sensitively by default, which is why a case-insensitive comparison wraps the value in Lower() (see String Comparison). Mirroring the casing shown in the JIM admin UI keeps expressions readable, but it is not required for them to work. For the wider picture of where JIM is case-sensitive and where it is forgiving, see Case Sensitivity.
Multi-Valued Attributes¶
A Multi-Valued attribute such as proxyAddresses or memberOf reads as every value it holds, in every expression: none reads as nothing (null), one reads as that value, and several read as every distinct value in a fixed order (text by ordinal, so upper case before lower case; numbers ascending; dates oldest first; Guids and references by their text). The order does not depend on how the Connected System returned the values, so an expression gives the same answer after every import. An attribute declared Multi-Valued but holding one value, as cn, mail and givenName usually do in a directory, behaves exactly like a Single-Valued one.
Functions work with several values in four ways:
- Transforms apply to each value and return every result, in the same order:
Trim,Upper,Lower,Capitalise,Left,Right,Substring,Replace,RegexReplace,RegexExtract,EscapeDN,ToString,FormatDate,ParseDateandFromFileTime. - Comparisons are true when any value satisfies them, as a scoping criterion on a Multi-Valued attribute is:
Eq,StartsWith,EndsWith,ContainsandIsMatch.!in front of one therefore means "no value does". - Whole-set functions work on the set itself:
Count,Min,Max,JoinandWhere(see Multi-Valued Functions). - Everything else needs one value: joining text with
+, the comparison and arithmetic operators,.ToString(), andLength,ToInt,ToDecimal,ToFileTime,HasBit,SetBit,ClearBit,EnableUser,DisableUserandSplit. One value is used as it is; several are an error on the object, naming the attribute and how many values it has.== nulland!= nullstill test whether there is a value.
For an object whose proxyAddresses holds SMTP:priya.shah@example.org and smtp:p.shah@example.org:
| Expression | Result |
|---|---|
cs["proxyAddresses"] into a Multi-Valued attribute |
both addresses |
Lower(cs["proxyAddresses"]) |
both addresses, lower-cased |
StartsWith(cs["proxyAddresses"], "SMTP:") |
true (one address does) |
!StartsWith(cs["proxyAddresses"], "x500:") |
true (no address does) |
Count(cs["proxyAddresses"]) |
2 |
Join(cs["proxyAddresses"], ";") |
SMTP:priya.shah@example.org;smtp:p.shah@example.org |
Where(cs["proxyAddresses"], "starts with", "SMTP:") |
SMTP:priya.shah@example.org |
Replace(Where(cs["proxyAddresses"], "starts with", "SMTP:"), "SMTP:", "") into Email |
priya.shah@example.org |
cs["proxyAddresses"] into a Single-Valued attribute |
an error on the object: proxyAddresses has 2 values |
A result with several values written to a Multi-Valued attribute writes every value; written to a Single-Valued attribute, it flows nothing and is reported as a Multi-Valued to Single-Valued error, the object's other attributes unaffected. The tester shows the same, so try an expression against several sample values before saving it.
Operators¶
You can use standard operators to combine values, do arithmetic, and make comparisons.
Joining Text¶
Use + to join text values together:
mv["First Name"] + " " + mv["Last Name"]
// If First Name is "Jane" and Last Name is "Smith", the result is "Jane Smith"
"CN=" + mv["Account Name"] + ",OU=Users,DC=company,DC=local"
Arithmetic¶
Standard maths operators work with numbers:
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ |
Add | 10 + 3 |
13 |
- |
Subtract | 10 - 3 |
7 |
* |
Multiply | 10 * 3 |
30 |
/ |
Divide | 10 / 3 |
3 |
% |
Remainder | 10 % 3 |
1 |
Comparisons¶
Compare values using these operators. The result is either true or false:
| Operator | Meaning | Example | Result |
|---|---|---|---|
> |
Greater than | 10 > 3 |
true |
< |
Less than | 10 < 3 |
false |
>= |
Greater than or equal to | 10 >= 10 |
true |
<= |
Less than or equal to | 3 <= 10 |
true |
== |
Equal to | 10 == 10 |
true |
!= |
Not equal to | 10 != 3 |
true |
Each side of a comparison operator is one value: comparing a Multi-Valued attribute holding several values is an error, so use Eq() or Where() for those (see Multi-Valued Attributes).
Logic¶
Combine multiple conditions using logical operators:
| Operator | Meaning | Example | Result |
|---|---|---|---|
&& |
AND | 10 > 3 && 5 > 2 |
true |
\|\| |
OR | 10 > 3 \|\| 5 < 2 |
true |
! |
NOT | !(10 > 3) |
false |
Example: check that an employee is both active and in the IT department:
String Comparison¶
== and Eq() both compare text by its characters, exactly and case-sensitively:
They differ in two ways. Eq() is true when any value of a Multi-Valued attribute is equal, where == needs one value. And Eq() reads text against a typed value as that type, so Eq(mv["Hire Date"], "2026-03-15") compares dates.
For case-insensitive comparisons (where "Active", "ACTIVE", and "active" should all match), wrap the value in Lower() first:
Built-in Functions¶
String Functions¶
| Function | Description | Example |
|---|---|---|
Trim(value) |
Remove spaces from the start and end | Trim(mv["Name"]) |
Upper(value) |
Convert to uppercase | Upper(mv["Name"]) |
Lower(value) |
Convert to lowercase | Lower(mv["Name"]) |
Capitalise(value) |
Capitalise each word (handles hyphenated names like "O'Brien-Smith") | Capitalise(mv["Name"]) |
Left(value, count) |
Take the first N characters | Left(mv["Name"], 3) |
Right(value, count) |
Take the last N characters | Right(mv["Name"], 4) |
Substring(value, start, length) |
Extract a portion of text | Substring(mv["Name"], 2, 4) |
Replace(value, old, new) |
Replace one piece of text with another | Replace(mv["Email"], "@old.com", "@new.com") |
Length(value) |
Count the number of characters | Length(mv["Name"]) |
IsNullOrEmpty(value) |
Check if there is no value: missing, blank, or a Multi-Valued attribute with no values | IsNullOrEmpty(mv["Name"]) |
IsNullOrWhitespace(value) |
Check if there is no value, or only spaces | IsNullOrWhitespace(mv["Name"]) |
HasValue(value) |
Check if there is a value: the opposite of IsNullOrEmpty |
HasValue(mv["Manager"]) |
StartsWith(value, prefix[, ignoreCase]) |
Check if text begins with a specific value, exactly unless ignoreCase is true |
StartsWith(mv["Email"], "admin") |
EndsWith(value, suffix[, ignoreCase]) |
Check if text ends with a specific value, exactly unless ignoreCase is true |
EndsWith(mv["Email"], "@company.com") |
Contains(value, search[, ignoreCase]) |
Check if text contains a specific value, exactly unless ignoreCase is true |
Contains(mv["Email"], "@company") |
StartsWith, EndsWith and Contains compare character by character, exactly as the scoping operators of the same names do: StartsWith(mv["Email"], "ADMIN", true) ignores case.
Pattern Functions¶
These use .NET regular expressions, the same as the matches pattern scoping operator. A pattern is matched exactly unless ignoreCase is true, and each match has a time limit of 100 ms: a pattern that runs past it (nested repetition such as (a+)+ is the usual cause) fails the object with an error rather than guessing. A pattern that is not a valid regular expression is an error too.
| Function | Description | Example |
|---|---|---|
IsMatch(value, pattern[, ignoreCase]) |
Check if text matches a regular expression, true when any value of a Multi-Valued attribute does | IsMatch(cs["employeeId"], "^E[0-9]{6}$") |
RegexReplace(value, pattern, replacement[, ignoreCase]) |
Replace every match of a regular expression; the replacement can use $1 for the first group |
RegexReplace(cs["phone"], "[^0-9+]", "") |
RegexExtract(value, pattern[, group]) |
The first match of a regular expression, or the group named by number; nothing when it does not match | RegexExtract(cs["mail"], "@(.+)$", 1) |
Conditional Functions¶
| Function | Description | Example |
|---|---|---|
IIF(condition, trueValue, falseValue) |
Return one value if a condition is true, another if false | IIF(Eq(mv["Status"], "Active"), 512, 514) |
Coalesce(value1, value2) |
Use the first value if it has one (not missing, blank or an empty list), otherwise use the second | Coalesce(mv["Preferred Name"], mv["First Name"]) |
Eq(value1, value2) |
Check if two values are equal, true when any value of a Multi-Valued attribute is; a date compares by instant | Eq(cs["memberOf"], "CN=Admins") |
Conversion Functions¶
| Function | Description | Example |
|---|---|---|
ToString(value) |
Convert a value to text | ToString(mv["EmployeeId"]) |
ToInt(value) |
Convert text to a whole number (returns 0 if not a valid number) | ToInt(mv["Age"]) |
ToDecimal(value) |
Convert to an exact decimal number: text is read with . as the decimal point, and accepts exponent notation (1.5E3 is 1500). Returns 0 if not a valid number |
ToDecimal(cs["Salary"]) |
Date Functions¶
| Function | Description | Example |
|---|---|---|
Now() |
Current date and time (UTC) | Now() |
Today() |
Current date at midnight (UTC) | Today() |
FormatDate(value, format) |
Write a date, or ISO 8601 text, in a .NET date format; nothing for other text or no value | FormatDate(mv["Hire Date"], "yyyy-MM-dd") |
ParseDate(text, format) |
Read text in a .NET date format as a date, in UTC unless the format has an offset (zzz or K); nothing for empty text, an error for text that does not match |
ParseDate(cs["hireDate"], "dd/MM/yyyy") |
ToFileTime(date) |
Convert a date, or ISO 8601 text, to Active Directory's FILETIME format | ToFileTime(mv["Account Expires"]) |
FromFileTime(filetime) |
Convert an Active Directory FILETIME back to a date | FromFileTime(cs["accountExpires"]) |
Now() and Today() return a different value as time passes, as do RandomPassword(), RandomPassphrase(), DateTime.Now, DateTime.UtcNow, DateTime.Today and Guid.NewGuid(). The value then changes on every synchronisation and, from an import Attribute Flow that derives a Metaverse attribute, can be exported every time, so JIM warns when you save an Attribute Flow that calls one (it still saves it).
Dates and Numbers as Text¶
Writing. Whatever the server's language, ToString(), a date flowing to a Text attribute, and the tester write a date as 2026-03-15 10:30:00Z: UTC, with a fraction of a second only when there is one. Joining a date to text with + writes the same form, because every date an expression reads is in UTC, to the microsecond. Numbers use . as the decimal point. For any other form, use FormatDate():
"Changed " + ToString(mv["Last Changed"]) // Changed 2026-03-15 10:30:00Z
FormatDate(mv["Last Changed"], "dd MMM yyyy") // 15 Mar 2026
Reading. Text, including text flowing to a DateTime attribute, is read as a date only in ISO 8601: yyyy-MM-dd, then optionally T or a space and a time (HH:mm, optional seconds and fraction), then Z, an offset such as +01:00, or nothing, which means UTC. Every other form is refused, including 03/04/2024, which is 3 April in one country and 4 March in another; read those with ParseDate():
ParseDate(cs["startDate"], "dd/MM/yyyy") // 15/03/2026 is 15 March 2026, 00:00 UTC
ParseDate(cs["changed"], "yyyyMMddHHmmssK") // 20260315103000Z is 15 March 2026, 10:30 UTC
A ParseDate() mismatch is an error, not "no value", so an unexpected form never clears the attribute. A Binary value has no text form: text functions such as Upper() refuse it with an error, while IsNullOrEmpty() and IsNullOrWhitespace() treat it as a value.
Distinguished Name (DN) Functions¶
| Function | Description | Example |
|---|---|---|
EscapeDN(value) |
Safely escape special characters for use in LDAP distinguished names | "CN=" + EscapeDN(mv["Display Name"]) + ",OU=Users,DC=domain,DC=local" |
Password Generation¶
| Function | Description | Example |
|---|---|---|
RandomPassword(length, extendedChars) |
Generate a random password. Set extendedChars to true for special characters (!@#$%^&*) |
RandomPassword(16, true) |
RandomPassphrase(wordCount, separator) |
Generate a passphrase from random words | RandomPassphrase(4, "-") |
Multi-Valued Functions¶
These functions work on every value of a Multi-Valued attribute at once.
| Function | Description | Example |
|---|---|---|
Count(values) |
How many values there are: 0 for none | Count(cs["proxyAddresses"]) |
Min(values) |
The smallest value: numbers by value, dates by instant, text by ordinal; nothing for no values | Min(mv["Start Dates"]) |
Max(values) |
The largest value, compared as Min compares |
Max(cs["employeeNumbers"]) |
Where(values, operator, value[, ignoreCase]) |
The values that meet a scoping operator, named as the editor shows it ("starts with") or as the REST API names it ("StartsWith"); text compares exactly unless ignoreCase is true |
Where(cs["proxyAddresses"], "starts with", "SMTP:") |
Split(value, delimiter) |
Split a delimited text value into several values, in the order they appear | Split(cs["coursesCompleted"], "\|") |
Join(values, delimiter) |
Combine values into a single delimited text value, in the order they are read | Join(mv["Groups"], ",") |
Min and Max refuse values they cannot order (true or false, Guids, Binary, or a mix of kinds) with an error, and Where refuses has a value and has no value, which test an attribute rather than each value: use Count or IsNullOrEmpty.
Account Control Functions¶
These functions are primarily used with Active Directory's userAccountControl attribute, which stores account settings as a single number using individual bit flags.
| Function | Description | Example |
|---|---|---|
EnableUser(uac) |
Enable a user account | EnableUser(cs["userAccountControl"]) |
DisableUser(uac) |
Disable a user account | DisableUser(cs["userAccountControl"]) |
SetBit(value, bit) |
Turn on a specific flag | SetBit(mv["uac"], 65536) |
ClearBit(value, bit) |
Turn off a specific flag | ClearBit(mv["uac"], 65536) |
HasBit(value, bit) |
Check if a specific flag is turned on | HasBit(cs["userAccountControl"], 2) |
Nulls, Missing Inputs, and Whitespace¶
When an expression references an attribute the object does not have, it sees null, and how JIM treats that decides whether a target value is cleared, kept, or silently filled with malformed data. Read Nulls and Missing Inputs before you write an expression that references an attribute which might be absent: it sets out the five rules, and the per-mapping setting that has JIM refuse an outcome rather than guess at it.
Expression Recipes¶
Worked expressions for the Attribute Flows most deployments need, such as enabling Active Directory accounts from an employment status, building email addresses and distinguished names, and splitting delimited values into a list, are on Expression Recipes.
Validation and Troubleshooting¶
Testing an expression¶
The Attribute Flow dialog tests an expression as you write it, so you find out what it produces before you save it rather than from the next synchronisation.
Choose Expression as the source type, choose the target attribute, and type your expression. The Try it pane lists each attribute the expression reads, with its type and whether it holds several values. Give each a value and it shows what a synchronisation would do, using the same code, updating as you type or change the settings.
Giving the inputs values:
- Each value is read as its attribute's type. Type
2026-03-02for a date and time attribute and the expression receives a date, soFormatDate((DateTime)cs["hireDate"], "yyyy-MM-dd")produces2026-03-02. A value that is not of the attribute's type is reported, naming the input. - A multi-valued attribute takes several values. Type each one and choose Add value.
- No value is a tick box. An input you leave untouched has no value. Tick No value to make an input absent again after typing in it. Clearing the box gives the input empty text instead, which the expression sees as empty text rather than null. Missing Input Behaviour treats both as missing, as a synchronisation does.
- Run as of sets the date and time (UTC) that
Now()andToday()return, so an expression that depends on the date can be checked for the day it matters. Leave it empty for the current time. - From an object fills the inputs from a real object: search for a Connected System Object of the rule's Connected System for an import Attribute Flow, or a Metaverse Object for an export one, and pick it. Its values for each input are loaded, every value of a multi-valued attribute included, and you can change any of them to try a variation. An import Attribute Flow that reads
mv["..."]also takes those inputs from the Metaverse Object the Connected System Object is joined to.
Reading the result. What a Synchronisation would do traces each step:
- Expression returned: the expression's own result and its type, or why it was not evaluated or failed.
- Value processing: the Attribute Flow's trimming, whitespace and case settings, in the order they apply, and whether they changed the value. It applies to an import Attribute Flow into a Text attribute only.
- Converted for the target: the values the target attribute would hold, in its type.
- Result: what the target would be given: these values, no value, or the error a synchronisation would record, such as a result the target's type cannot hold.
If an input has no value then runs the flow again for each input you gave a value, with that one input absent, and shows what the Attribute Flow's Missing Input Behaviour would do. Change opens that setting. This is how you check an expression against the hazard the previous section describes:
With both values supplied this produces ada.lovelace@corp.local. Without the surname it produces ada.@corp.local, a syntactically fine string that is not an email address, unless Missing Input Behaviour stops it. Seeing that before saving is the point.
Before a target attribute is chosen, the expression is evaluated on its own, with each value as text, and an empty box is no value.
The same test is available outside the portal, over Test-JIMExpression and the REST API's /api/v1/synchronisation/test-expression, for testing an expression from a script. Give the Synchronisation Rule and Attribute Flow to test the expression as that Attribute Flow, and optionally a Connected System Object or Metaverse Object to load the values from; without them, the expression is evaluated on its own. Either way, -AsOf (asOf over REST) sets the time Now() and Today() return. For a Generated Value, the test stops at the base, as a synchronisation does.
Validation¶
JIM checks an Attribute Flow's expressions when you save it, in the portal, the REST API and PowerShell alike, and refuses one that:
- does not parse, or calls a function there is none of;
- reads the wrong side: an export Attribute Flow reading
cs["..."], which it never has; - reads an attribute the object type does not have, so that input never has a value;
- returns a type its target can never hold, where that is known before it runs: for example
HasValue(...), which returns true or false, flowing to a DateTime attribute. Only an expression whose outermost call is a built-in function has a known type, so anything else is left to the tester.
The portal shows the reason under the field as you type, from the same check. A non-repeatable function is allowed, with a warning.
The check applies in full to an Attribute Flow you add, or whose expression or target you change. One that a save leaves as it was is never refused: its problems come back as warnings instead (a snackbar in the portal, warnings in the REST API's response, and a PowerShell warning). So you can always disable a Synchronisation Rule, or remove an Attribute Flow, while another one is broken. An Example Data Template's expressions are checked the same way; one reading an attribute the template does not generate is only a warning, because a template is built an attribute at a time.
Common errors:
- Missing closing quote or bracket
Check that every"and(has a matching pair. - Unknown function name
Check the spelling; function names are case-sensitive. - Wrong number of parameters
Check the function reference above for the correct parameters. - Syntax errors
Look for misplaced operators or missing commas between function parameters.
Troubleshooting¶
When an expression does not produce the result you expect:
- Check the attribute name spelling
Attribute names are matched case-insensitively, somv["department"]andmv["Department"]are equivalent; casing is never the cause. Do check the name is spelled correctly and matches an attribute that exists in the JIM admin UI. - Check for several values
A Multi-Valued attribute holding more than one value is an error where one value is needed, naming the attribute; choose one withWhere(),Min()orMax(), or combine them withJoin()(see Multi-Valued Attributes). - Check for missing values
If an attribute does not exist on the object, it returns nothing (null), which can clear the target or, in a concatenation, produce a malformed value. UseCoalesce()orIsNullOrEmpty()to handle this; see Nulls, Missing Inputs, and Whitespace for the full picture. - Test with sample data
Use the tester in the Attribute Flow dialog to try your expression with sample values, including leaving an input empty to see what an object without that attribute would produce (see Testing an expression). - Check the worker logs
If expressions fail during sync, the worker service logs the error details.
Best Practices¶
-
Say which value of a Multi-Valued attribute you mean
UseWhere(),Min(),Max()orJoin(), so an object gaining a second value is handled rather than reported as an error. -
Handle missing values
UseCoalesce()to provide a fallback, orIsNullOrEmpty()to check before using a value. This prevents an expression clearing the target or writing malformed data when an attribute has not been populated yet; see Nulls, Missing Inputs, and Whitespace. -
Always use
EscapeDN()in distinguished names
This prevents special characters in names from breaking LDAP paths. -
Test before saving
Use the expression test feature in the UI to verify your expressions with sample data. -
Keep expressions simple
If an expression is getting complex, consider splitting the logic across multiple attribute mappings. -
Document complex expressions
Add a note in the Synchronisation Rule's description explaining what complex expressions do, so the next person can understand them.