Manipulating string is probably the most frequent operation we need to do when transforming data. Thus, I’d like to talk a bit about string concatenation in WebMethods. The most basic way to add two strings is to use the pub.string.concat service in the WmPublic package as shown below:

However, this approach is way too limited. For example, to combine a Unique ID string that consists of a Prefix, an auto ID number, a Suffix with a separator in between such as: WO-10012-CM, we’ll need to use at minimum 4 lines of code, and a number of temporary variables. That’s crazy.
An alternative approach is to use variable substitution when assigning values to a variable as shown below. In this case, we can build a new string from an unlimited number of variables in just one line of code.

This approach doesn’t work if one of the input variables can have a Null value. In that case, it will give us an unwanted result as shown below:

With the Tundra library, we have a much more flexible tundra.string.concatenate service. It allows us to add an unlimited number of strings in one line, and at the same time, have some other capabilities such as adding a separator.

In the example above, I can achieve the same result in one line of code, and the tundra service is smart enough not to add the second separator when the $suffix variable is Null.
However, beware of the annoying bug with WebMethods that it doesn’t have the ability to set the order of input variables. Thus, when you make an update to one input, for example, in the example below, I changed the input variable str2 to map it to a different variable, it will move to the bottom of the list, and thus, messed up the final output.

A workaround is to update the other variables manually to correct the order. But from my experience, anything having more than 3 inputs will be a maintenance nightmare.

The more robust approach is to write our own concatenate service as part of a common service package. It can take a bit of time, but if we have a big project, it’s worth the effort to build some common service library to be reused across the entire environment. Ten minutes spent on building this service can save the whole team a countless hours in development and maintenance.
Edit: After reading this post, Lachlan Dowding, Tundra library’s author, told me we can use String List to workaround the WebMethods’s bug on changing the order of input strings when using Tundra’s concatenate.