cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

TIP: (Safely) Concatenating Strings that might be NULL

RussellJ
Deputy Chef III
Deputy Chef III

I was today years old when I came across this simple solution so thought I'd post it!

I often find I want to concatenate two or more strings together, usually when trying to formulate a friendly error message for a log or an email to a human when something's not quite worked right.

However, you can't safely just use...

no conv.jpg

... because if either or both values contains a NULL, Workato throws an error.

I started to head down the ternary operator route (which felt overly complicated and difficult to read) and then stumbled across the use of ".to_s" for each data pill to force convert the data pill to a string...

to_s.jpg

Now, if either value contains NULL the result is an empty string (which Workato is then happy to "squish" with another string).

Realise it's very basic, but thought I'd share in case someone else might find it useful.

Tune in next week for "Russell learns to pat his head and rub his tummy at the same time"...

[waits for @gary1  to jump in with an even better, more elegant solution...]

0 REPLIES 0