The Feed Doctor's New Business Rule Functions
Have you ever wondered how we decide on the different functions that we build into the business rule system? Today I’ll tell you the story of two brand new ones.
I get asked to help write lots of complex business rules. Usually, I can figure out a solution, but sometimes it’s not pretty. If it’s a problem that comes up a lot, sometimes I like to create a brand new function to help make it simpler. Here's a recent example where I was asked for help on writing a rule. The input to the rule is a comma-separated list of values. The rule should output as many whole values in the list as possible so that the total length of the output is less than 50 characters. So for example, if the input is:
Then the output should be:
You can easily do the part about "less than 50 characters" using the LEFT function, but if you do that, you get this:
So, you have to do some REGEX magic to cut off that last comma and letter j, and it can get messy. It turns out, I've helped people with this very problem several times; I even wrote a blog post on it LONG ago: The Feed Doctor Makes a Long Story Short.
Finally, I decided it was time to build this function into the system. I created a new function, LEFTWORD. You give it the input text, the maximum length, and a "delimiter," which can be anything; in our example, it would be a comma. If you have a list of words and you want to “chop” it on word boundaries, you can use a space. If you have several sentences and you want to chop at sentence boundaries, use a period.
Another thing I like to do from time to time is take a look at some of the patterns of business rules that people write. If I see that numerous people are writing long, complex rules to solve the same problem, it’s obvious that there's an opportunity to create new functions. Here’s a pattern that we’ve had, basically forever: Write a rule that outputs value #1, unless it's blank, in which case it outputs value #2, unless that's blank, in which case it outputs value #3, unless...you get the picture. You can do this with the IFBLANK function, but since IFBLANK only allows two inputs, you have to "nest" the IFBLANK calls, like this:
IFBLANK(IFBLANK(IFBLANK("value #1","value #2"),"value #3"), "Value #4")
What a pain! Why can’t IFBLANK be more like CONCATENATE and JOIN, which can accept a variable number of inputs? Why indeed. So, I decided to fix that, too. Now IFBLANK will accept up to 8 inputs, and will output the first (i.e., "leftest") one that is not blank:
IFBLANK("value #1","value #2","value #3","Value #4")
These changes rolled out yesterday along with other updates that are included here in the complete Release Notes.
For more information on comparison shopping best practices, download 16 Common Comparison Shopping Mistakes to Avoid at All Costs.
Blog post by Anthony Alford, (a.k.a. The Feed Doctor), Technical Lead (Follow him on twitter @TheFeedDoctor)