Nintex Workflow

Nintex Workflow – When Inline Functions don’t work

Inline Functions are a great extension to Nintex Workflow.  They open up the ability to do some amazing string manipulation.  But what happens when they don’t work?  Why don’t they work?

Scenario 1

A text variable (textSample) has the value “Hello world” and you want to replace “world” with “universe”.  You can use a Build String action and a fn-Replace inline function call.

fn-Replace({WorkflowVariable:textSample},world,universe)

This will work.  The result will be “Hello universe”.

What if instead, your input test was “Hello, world”. – Notice the comma after the Hello.  When you run the above inline function call, it won’t work and you’ll get this back:

fn-Replace(Hello, world,world,universe)

Why does this happen?

The fn-Replace function supports only 3 parameters.  But the way the parsing of inline functions works, is that it first replaces any variables, fields, properties with their real values before parsing the inline function itself.  In this case, we end up with 4 parameters to the fn-Replace function call.  As it only support 3, we get the full string back.

The same sort of thing would happen if your input text was fine, but your text you want to replace or the replacement text contains a comma.

Fix

To fix this, Nintex has come u[ with a wrapping scheme, whereby you wrap any of the inline function parameters in between a {TextStart} and {TextEnd}.

So the function calls becomes this:

fn-Replace({TextStart}{WorkflowVariable:textSample}{TextEnd},world,universe)

In this case, the input is parsed correctly and the result will be “Hello, universe”.

Scenario 2

Embedded inline function calls.

Again, our input will be “Hello, world” – notice the comma again.

We want to replace “Hello” with “Goodbye” and “world” with “universe”.

Although we could do this with multiple Build String actions, my preference is to keep the number of actions in my workflow to a minimum.  Any time I can minimize my workflow, I do it.  It may take longer to design the workflow, or require more investigation, learning, redesigning, but I guarantee you it is worth it.  If you’ve ever build a large workflow ( > 1mb when you export the workflow ), you know what I’m talking about.

So the thing to take from this, is that you can call inline functions within inline functions.

eg.

fn-Replace(fn-Replace({WorkflowVariable:textSample},Hello,Goodbye),world,universe)

The above call will work, if we have no commas in our input text or other parameters.  But if you do, it’ll break.

The common mistake here, is wrapping only the variable in the TextStart, TextEnd.

fn-Replace(fn-Replace({TextStart}{WorkflowVariable:textSample}{TextEnd},Hello,Goodbye),world,universe)

Also this looks like it will work, the result will be this:

fn-Replace(Goodbye, world,world,universe)

This is because the inner function call will be evaluate first.  The result will “Goodbye, world”.  As you can see, there is a comma in the result and then this will be passed to the outer inline function call.  Resulting in 4 parameters being passed to fn-Replace instead of 3.

The solution to this would look like this:

fn-Replace({TextStart}fn-Replace({TextStart}{WorkflowVariable:textSample}{TextEnd},Hello,Goodbye){TextEnd},world,universe)

Where to find Inline Functions

If you can’t remember which inline functions you have available, add a Build String action and in the configuration of it, click the Insert Reference button.  You’ll find a tab for Inline Functions:

Inline Functions

The names you see there are the display names.  You’ll find when you add them to a Build String action, they’ll get a “fn-” in front of them.

Conclusion

I hope this helps people figure out why your inline functions aren’t working as expected and get them working as you want.

Leave a Reply