All right, I’m sure we’ve all finally finished the Harry Potter book and now we can get back to work. But just in case some readers haven’t finished, this post is guaranteed Harry-Potter-spoiler-free. As long as you don’t click on this link.

I know we’re all tired of lookup lists, so just one more, I promise. This week, “L.” in French Lick, IN, writes:

Dear Feed Doctor,

I have several items that are on sale. The sale price is in my inventory system, so that’s going into my shopping feeds just fine. I can get a 1-column list of the skus that are on sale. Can I write a business rule that will make sure that ONLY these items are included in my shopping engine feed?

Now that’s an interesting twist. All the lookup lists we’ve been working with so far have been key/value pairs, and in fact, everything I say in this blog post also applies to lists of key/value pairs. However, sometimes you have situations that are more like what people think of as just plain old lists; instead of a phone book, think of a guest list. Technically speaking, the guest list is a one-dimensional array, where the phone book is two-dimensional array. Here’s how L. might enter his list:

list definition

Filters and ISINLIST
Now, it’s true that a one-dimensional array like this isn’t as powerful as the two-dimensional key/value ones we’ve been working with. A guest list can’t answer the question “given a person’s name, what is her phone number?” but it CAN answer the question “given a person’s name, is she on the list?” Just as ShoppingAdvisor has a function (LOOKUP) to answer the first question, it has a function called ISINLIST that answers the second question. Unlike LOOKUP, which outputs the value associated with the input key, ISINLIST outputs only “True” or “False.” This is sometimes called a Boolean function, and it’s great for writing business rules that have to make a decision. Remember: ISINLIST works just fine on lookup lists with values; you can use a phone book to decide whether or not a person is in the phone book as well as to find out her phone number.

bad filter

Let’s go back to L’s problem. He’s got a list of skus, and, just like the bouncer at the door of the club, he’s not letting anybody in who isn’t on the list. In ShoppingAdvisor, we call this a filter, and it’s nothing more than a business rule that outputs “True” or “False.” You can think of it like this: the filter is asking “Should I exclude the item?” If the rule returns “True”, the item is excluded; if it returns false, the item is not excluded. So suppose L. wrote a rule something like this: ISINLIST("Sale Items",$model)

Would that do it? Let’s say the item sku is “BB-63.” That’s in the list, so ISINLIST returns “True.” So the filter excludes the item. Wait a minute! That’s backwards! The filter needs to do the opposite of what ISINLIST says. Fortunately, ShoppingAdvisor has just such a Bizarro function: NOT. (Okay, every computer system ever invented has NOT built-in, but there might be some people who didn’t know that. NOT.) Here’s a rule that does what L. wants:

sale price filter

Now all L. has to do is save that, then go to his feed template and apply the filter, down at the bottom of the page:
applying sale filter

If, Then, Else
That was a nice little exercise in Boolean logic; haven’t had so much fun since I had to do proofs in high school geometry. Filters are great, and everybody knows that sometimes it’s good to exclude items from your feeds for various and sundry reasons. However, sometimes you also need to write rules that make decisions about what to put in the content of outgoing feeds. For example, suppose L. doesn’t want to filter out the non-sale items; instead, he wants to put an “On Sale” promotional message in his shopping feeds for the sale items (the non-sale items would just have their normal promotional text from some inventory field).

In other words, he wants a rule that does something like: IF the item is on sale, Then output “On Sale, Otherwise output the promotional text inventory field. Again, pretty much every computer system does this (it’s usually called an “If/Then/Else” construct). In ShoppingAdvisor, L. can use the IF function. Here are the inputs:

  • A Boolean “test” value
  • An “if true” value that is returned if the test is true
  • An “if false” value that is returned if the test is false

IF is a lot like IFBLANK; in fact, you can think of IFBLANK as a special case of IF that you don’t have to give a test value to. The test is built in: is the “if true” value not blank? Here’s L’s rule:

list definition

And the template using the rule:
list definition

Are You Out of Your Vulcan Mind?
These “True or False,” “If/Then/Else” scenarios are applications of Boolean Logic. ShoppingAdvisor business rules can use several Boolean-valued functions (including ISINLIST), as well as your standard Boolean operators (AND, OR, NOT) and comparison operators (=, >, <) that you can use to create complex filters. Also, there are other functions with Boolean inputs, besides IF, that you can use to create sophisticated rules for manipulating your inventory data. Want to know more? Just ask the Feed Doctor.