TRIM in expression language

Hi all, In the profile editor at the mapping I am trying to trim (remove heading and trailing) spaces from some fields. The case can be that a value of a field starts or ends with 0, 1 of more spaces. I tried to use String.replace but the spaces between words should be kept. I tried regex expressions with String.replace, but this doesn’t work. Any idea’s how to solve this without a boilerplate of code?
Thanks in advance.

The Okta Expression language is maybe an awkward match for what you’re trying to do. It doesn’t support regular expressions (except for specific functions).

Can you provide some examples of the types of values that exist for these attributes and what they need to be converted to? Also, when does this conversion need to happen (in case there’s a way to do this outside of the profile mappings)?

Hi Andrea, Thanks for your reaction. From our HR-system we get name-fields like Nickname, middle name/prefix and lastname and also the partner’s middle name and lastname. In the Netherlands you can choose a combination of these names:

  1. Just your own name
  2. Partnersname
  3. your own name-Partnersname
  4. Partnersname-your own name.

We also get the choosen option from the HR-system. The applications where we provision accounts to are sometimes expecting the format nickname [middlename(if any)] lastname(-combination) and sometimes lastname(-combination), nickname [middlename(if any)] . So for convenience I want to have a couple of these combinations available in the Okta profile. But sometimes HR/Managers enters 1 or 2 spaces before or after those names. Some employees have also 2 nicknames like “John Bob”, so replacing all spaces by nothing is not an option.
Thanks in advance.

I don’t see an easy way to achieve this using the expression language. You would more or less need a function that is able to convert the names based on your criteria. Leading spaces you could maybe catch with checking String.substringBefore(name, " ") and then using replaceFirst, but it might end up being more trouble than its worth to write a more complicated expression to do this.

Have you looked into using something like Workflows to help with this mapping/conversion?

Hi Andrea, In Okta Workflows it should be very easy, because you can use regex, trim etc. Our implementation partner advises us not to use workflows for this purpose, because of performance/complexity. Is that so? If we implement this in Workflows, every new user or a name change causes calls to workflows.
What is your advice?

I’d recommend checking out our Workflows Office Hours and see if you can to get some help/advice about your use case, as they are more specifically focused on this product than I am: Calendly - Okta Workflows.

There’s also a lot of good information about Workflows here: Okta Workflows | Okta

Thanks Andrea for this information :grinning:.