Okta Expression to get a positioned value from user DN Skip to main content
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.
Ask Search:
Nidhin C KNidhin C K 

Okta Expression to get a positioned value from user DN

We are trying to get OU name from user distinguishedname attribute to a custom attribute. 
User DN eg:- 
CN=Nidhin C K,OU=Users,OU=XXX,OU=XX,DC=region,DC=dc,DC=company,DC=com

From this above value we just need to pull XXX (its position will not change, ie no of characters from right to left won't change). 

we cannot use String.substring(appuser.dn, 2, 9) as this command calculate value from left to right.  In our scenario "OU=XXX,OU=XX,DC=region,DC=dc,DC=company,DC=com" is constant. ie its position or no of characters wont change.

Is there a way to get only XXX from user DN using expression
Adam LoweAdam Lowe (Okta, Inc.)
Linked below is Okta's documentation on the Expression Language:

From what you described, it sounds like String.substring function would work, but the position from left to right will always be different, given the CN will be different dependon on the users name.  So perhaps we could make String.substring work, if we could remove the CN portion of the string first.

Try including String.substringAfter(appuser.dn, "OU=Users,")

Once that portion of the string is removed, you can then use the String.substring function.
Nidhin C KNidhin C K
Hi Adam,

Only "OU=XXX,OU=XX,DC=region,DC=dc,DC=company,DC=com" will not change (no of characters from left to till OU=XXX). 

A user can be located multiple sub OU's  for eg:- 
CN=Nidhin C K,OU=IT,OU=AD,OU=Users,OU=XXX,OU=IN,DC=region,DC=dc,DC=company,DC=com

I just need to pull OU named XXX . So is there any way to pull the OU named XXX