Mihai N. (Okta, Inc.) asked a question.
Okta Expression Language (OEL)
Writing custom expressions to manipulate usernames, format phone numbers, or handle null claims. Here are Top 10:

We use cookies to provide the best website experience and to help understand marketing efforts. We may also share data with ad partners to reach potential customers across the web. To learn more, visit our Privacy Policy. Click here for Your Privacy Choices. You may also opt out of this sharing by signaling your preference via GPC, applicable only to the browser signaling the opt-out.
More information
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.
Select All
Ten of the most practical Okta Expression Language (OEL) expressions used across Profile Mappings, Group Rules, and SAML/OIDC claims:
1.Extract Username Prefix from Email (Profile Mapping / App Username)
String.substringBefore(user.email, "@")
Strips the domain from jane.doe@company.com to return jane.doe for legacy apps or SAMAccountName mappings.
2.Null-Safe Preferred Name Fallback (Profile Mapping / SAML Claims)
(user.nickName != null && user.nickName != "") ? user.nickName : user.firstName
Uses a ternary check to send a user's preferred name when populated and fall back to their legal first name when blank or null.
3.Generate Clean Lowercase first.last Emails (Inbound HR Mapping)
String.toLowerCase(String.replace(user.firstName, " ", "") + "." + String.replace(user.lastName, " ", "") + "@company.com")
Removes spaces from multi-word names and normalizes casing during HR-as-a-Master imports.
4.Strip Formatting from Phone Numbers (Profile Mapping / SMS MFA)
"+1" + String.replace(String.replace(String.replace(String.replace(user.mobilePhone, "-", ""), " ", ""), "(", ""), ")", "")
Converts (555) 123-4567 into +15551234567. Nested String.replace() calls are required because OEL performs literal string replacements rather than regex.
5.Swap Email Domains per Application (Profile Mapping)
String.substringBefore(user.email, "@") + "@newdomain.com"
Rewrites the email domain for a specific downstream app during rebrands or mergers without altering the user's primary Okta login.
6.Filter Groups by Prefix for SAML or OIDC Tokens (SSO Claims)
Groups.startsWith("active_directory", "APP_AWS_", 100)
Sends only Active Directory groups matching a specific prefix (up to the specified limit) to prevent token bloat. Replace "active_directory" with "OKTA" to target Okta-mastered groups.
7.Exclude Multiple Email Domains (Group Rules)
!(String.stringContains(String.toLowerCase(user.email), "@partner1.com") OR String.stringContains(String.toLowerCase(user.email), "@partner2.com"))
Combines negated String.stringContains checks with OR to separate internal staff from external contractors or partners. Wrapping user.email in String.toLowerCase() avoids mismatches since OEL string comparisons are case-sensitive.
8.Scope Group Rules to Active Users Only (Group Rules)
user.department == "Engineering" && user.getInternalProperty("status") == "ACTIVE"
Combines standard profile attributes with user.getInternalProperty("status") so suspended, staged, or locked-out users are excluded from dynamic app groups.
9.Match a Value Inside a String Array Attribute (Group Rules / Policies)
user.customRoles != null && Arrays.contains(user.customRoles, "Admin")
Checks multi-valued Universal Directory attributes while preventing null errors. Note that Arrays.contains performs an exact, case-sensitive full-element match and will not match substrings.
10.Pull a Manager's Attribute from a Linked Directory (SAML / SCIM / Profile Mapping)
getManagerUser("active_directory").email
Resolves the user's linked manager object directly from Active Directory (or another configured source) to pass the manager's email or login to downstream apps like ServiceNow or Jira.
Tip: OEL is strictly case-sensitive for both attribute names and string values—always test expressions against real profiles with the Preview button before activating a Group Rule or mapping in production.
For more information regarding Okta Expression Language please visit: https://developer.okta.com/docs/reference/okta-expression-language/