<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z0000A2BpBXCQ0Okta Classic EngineLifecycle ManagementAnswered2026-03-16T09:00:23.000Z2024-03-07T17:47:40.000Z2024-03-08T17:17:26.000Z

7jv04 (7jv04) asked a question.

Solving for users with multiple last names (surnames) when constructing the username.

Happy Friday Jr all (aka Thursday)! I'm solving for an issue and thought it might be a good one to share with the community.

I'm trying to figure out how to get around an error encountered while testing user profile import/creation in Okta Preview. When a user has multiple surnames (firstname, lastname, lastname, etc) it seems to be breaking the logic in the expression I created to construct the company email address in Okta. Error: "email Does not match the required pattern."

 

Users get an email address to be Firstname(or preferred first name if they have one)+Lastname@domain.com.

 

The expression works perfectly for user with a singular first name and singular last name:

Current email expression:

String.toLowerCase(appuser.PreferredFirstName == "" ? appuser.FirstName + appuser.LastName + '@domain.com' : appuser.PreferredFirstName + appuser.LastName + '@domain.com')

 

I'm trying to figure out how to select the first surname.

 

This is close, but split is not a valid property in the Okta expression language apparently and I'm struggling to find the right syntax:

String.toLowerCase(appuser.PreferredFirstName == "" ? appuser.FirstName + appuser.LastName.split(" ")[0] + '@domain.com' : appuser.PreferredFirstName + appuser.LastName.split(" ")[0] + '@domain.com')

 

This is also close but still invalid syntax:

String.toLowerCase(appuser.PreferredFirstName == "" ? appuser.FirstName + appuser.LastName.substringBefore(" ") + '@domain.com' : appuser.PreferredFirstName + appuser.LastName.substringBefore(" ") + '@domain.com')

 

I'm curious if others have encountered something similar, and how it was solved for.

Image is not available


  • TimL.58332 (Workflows)

    @7jv04 (7jv04)​ -- I don't have a solution for you. However, I recommend providing an "example" so it is better understood what you are trying to achieve. It is pretty odd to have two (attributes) with the same name that have different values. To the best of my understanding they would need to have two different unique variable names as these are effectively the "unique key" on a profile. If you can provide a more detailed description on the scenario with a mocked up user that demonstrates the problem && the desired outcome I suspect someone can help.

     

    for example do you mean something along the lines of:

     

    firstName = Tom

    lastName = jones white

    or

    lastName= jones-white

     

    Having a better understanding of the exact criteria is what I am talking about.

    Expand Post
    Selected as Best
  • TimL.58332 (Workflows)

    @7jv04 (7jv04)​ -- I don't have a solution for you. However, I recommend providing an "example" so it is better understood what you are trying to achieve. It is pretty odd to have two (attributes) with the same name that have different values. To the best of my understanding they would need to have two different unique variable names as these are effectively the "unique key" on a profile. If you can provide a more detailed description on the scenario with a mocked up user that demonstrates the problem && the desired outcome I suspect someone can help.

     

    for example do you mean something along the lines of:

     

    firstName = Tom

    lastName = jones white

    or

    lastName= jones-white

     

    Having a better understanding of the exact criteria is what I am talking about.

    Expand Post
    Selected as Best
  • 7jv04 (7jv04)

    Thanks for having a look Tim! After sleeping on the matter, I've decided that since there is no way to know for sure which surname a person wants to use in their identity, so the correct solution is to work with HR to change their process so the preferred identity is collected from the very beginning. But, for the sake of example: If we hired John Jacob Jingleheimer Schmidt, I was looking to construct the email address as so: johnjacob@domain.com... however, John may prefer Jingleheimer to be used, thus the practical course is to capture that in the hiring process. There just isn't a good way to automate that level of user preference without asking them directly.

    Expand Post
This question is closed.
Loading
Solving for users with multiple last names (surnames) when constructing the username.