RegEx In a Workflow - 101

Workflows in Kustomer are about as versatile as any old programmatic function. The deep inner workings of our extensive platform can be traversed nearly in its entirety with a precisely configured Workflow. Many of the options given when building out the Action step of a Workflow are presented in a way that makes an infinitude of options seem like a simple click away. And they -kind of- are.

But how do we take more direct control over the data we receive from an inbound Webhook? Or manipulate a field of predictably occurring figures to match the type of data passed into our Workflow?

What about when you’re looking to populate an attribute with a very particular value, gathered from a string of raw data? Or trying to exclude several positions of a string to reveal only the last four digits of extra-sensitive material? It can appear intimidating at times, but once you become familiar with using Regular Expressions, this becomes a very domitable task. 

I'll go through an example and walk you through, step-by-step, the process of excluding and returning particular sub-sections of a string to then carry elsewhere in your Workflows. 

In this example, we’ve been tasked with creating a Workflow to hide a Customer’s sensitive material, and store only the last four digits of their Credit Card information onto a custom Klass attribute in their Kustomer KObject. 

  • We’ll start by declaring a trigger for the Workflow. This can generally be any action that can be  monitored for changes throughout the platform. For this example, we’ll use raw order data from an order sent via a payload from an inbound form hook.

  • If we wanted to, and if our storefront processing platform provided us with the entire Credit Card number, we could just store the entire thing on the Customer’s instance for the whole office to see. But we’re more careful and considerate than that.

  • Instead of not being careful and/or considerate, we’re going to use RegEx to grab the last four digits of a 16-digit stringified number. Whether or not you’re familiar with RegEx as a tool is less important here. There are many tools around the web that can either teach you how to use RegEx, or just flat out use it for you. Here’s one that I see used on the team fairly often. 

  • Next, we’ll add a Generic RegEx Match action step in between where the incoming data is pulled and where the updated data will be stored. The TestString field will take in the string you’re looking to cut up with a RegEx operation. The RegEx(string) field will take the actual operation you’re looking to perform on the “patient”

  • This step will now output a value that is the result of our modifications. 

  • Finally, we come to our Customer Update action step, where we grab the value that was matched in our last step and plug it into our new custom attribute. Now we see the payload updating with the last four numbers of the ccInfo field rather than the whole thing.

And that’s it! We now have the requested data stored in the Customer object as 4 digits of a Credit Card number, rather than exposing the entire thing across our instance! Someone is going to be very grateful for that. 

Of course, there are always exceptions and different methods of accomplishing a task like this, but this method is clean and fairly easy to achieve with fewer steps than other crude workarounds out there. 

There are many other scenarios where a Generic RegEx Match step can help to trim or transform other types of input data. With a little ( honestly, a lot of ) RegEx practice and some imagination, sky’s the limit to the possibilities!