Download the Workflow : Click here to download
Note: This workflow was built in Nintex Workflow 184.108.40.206. If you are running an earlier build, it may not import.
After using the Nintex Workflow Query LDAP action to retrieve some information, I ended up getting it in a distinguished name format:
I needed to pull out the CN value. It's possible to do this with an Inline Function call like fn-SubString, but in order for that to work, you need to know exactly how long the substring is and it's position in the input string. Since the CN value can be any length, that would not work.
So the solution is to use a Regular Expression action, configured for an Extract.
The Regular Expression looks a little ugly, but it does what I need.
(?<=CN=) - Positive lookbehind. Matches the "CN=" before your main expression without including it in the result.
\w+ - Matches 1 or more of any word character (alphanumeric & underscore)
(?=,) - Positive lookahead. Matches a "," comma after your main expression without including it in the result.
This results in text between a CN= and a comma without include those bits of text.
This workflow is quite simple (3 actions). So I won't go into a great deal of detail. The screenshots should suffice.
Workflow looks like this :
We will need 3 variables.
Collection variable : to store the results of the regular expression extract.
Number variable : to keep the index 0 as the first index into the collection variable
Text variable : to then get the first value from the collection and store it here.
Next we add the Regular Expression action. I've typed in my input text, but if you use something like this, you'll have the input text in a variable or item field.
The results are in a collection variable. It's possible with an Extract that you will get more than one result. eg. if instead of CN= you used DC=, you'd get 2 results.
Now we need to get the first result from the collection and store it in a text variable.
Finally, I want to update my Title field for my current item, with the CN value that I extracted.
That's it. It doesn't really need more explanation than that.
This can be used to extract text from between any text strings, not just from a Distinguished Name. Hopefully, this helps some people who has this requirement, as I've had in the past.
I always look for a way to make my workflows smaller. Although a 3 action workflow is not exactly huge, when you start using this throughout a workflow, your workflow can grow quite quickly.
I have an idea to reduce this to 1 action. This will be something I will write about in a future post.