Business rules are powerful tools that allow you to customize and transform your data from the information you have to the information you need. They can help you cut down on the need for additional attributes, allow you to apply logic, use formulas, manipulate date, or filter items.
Business rules can also be intimidating and confusing to new users of ChannelAdvisor. This blog post is the first in a new series designed to demystify the process of writing your own business rules.
Types of Business Rules
Let’s start by discussing the two types of business rules; generally referred to as inventory and marketplace rules. Inventory rules act on data coming into ChannelAdvisor, and Marketplace rules act on data as it leaves ChannelAdvisor.
Inventory business rules are applied to an inventory template as data is brought into our system. They can reference columns in your upload file, but cannot reference data that already exists in ChannelAdvisor for the SKU. The output of these rules will be stored into an inventory field in ChannelAdvisor that you can then map to your marketplace templates. These rules can be found under Inventory > Product Mapping > Business Rules.
Marketplace business rules are applied to outgoing data templates. While they’re normally called marketplace rules, the same rules can be used for webstores or digital marketing. These rules can reference inventory fields that exist in ChannelAdvisor and alter the data that’s sent to the marketplace prior to being sent. The output of the rules won’t show in our system outside of rule and template previews. These rules can be found under many menus, but the most common are Marketplaces > Marketplace Name > Product Mapping > Business Rules.
Using the Business Rule Editor
Once you’re on one of the business rules pages, you can view existing rules or click on the ‘New Business Rule’ button in the upper left to create a new rule. This will open the business rule editor, as seen below (click to enlarge):
I’ve numbered certain portions of the screenshot so we can discuss them more easily.
- This is where you enter the business rule name and description. Make sure the name is as precise as possible so you can easily find the rule in the future. For example, if I’m making a rule to adjust the brand field on my Amazon template, I might call the rule “Amazon Brand Rule”. In the description, I can enter more details about the rule. It’s a good practice to use this space to describe in words what the rule is doing, as well as to save any previous versions of the rule if you are making changes to an existing one.
- The Editor is where you will compose or write the actual business rule function. We’ll come back to this in a moment and walk through writing a simple IF statement rule. The big thing to know now is that inventory fields are referenced with a $ and text strings need to be in quotes in rules.
- The ‘Reference’ section has three tabs that will show you your available inventory fields and how to reference them in a rule, the functions you have available, what they do, and how to format them, as well as the lookup lists you can use in your rules.
- Once you have a rule written in the Editor, you can use this section to pick a SKU you want to preview the rule on. This will allow you to see what the rule will output on a given SKU.
- Once you select a SKU in 4, the actual preview will show up here. Keep in mind that if you use variations some fields will send a parent SKU value to the marketplace, so what you see in the rule preview won’t always match what’s in the template preview. This is also where any errors, if any, will show up as you’ re writing the rule.
Writing a Business Rule
Now that we have the basics down, let’s start writing a rule. For this example, I’m going to write a rule that will take the brand name “Acme Co.” and send the value “Acme”. For all other brands, it should send the brand name unchanged.
First, we’ll want to look at the Inventory Fields and Functions tabs under ‘Reference’ to find what we’ll need to build the rule. Under ‘Inventory Fields’, we see ‘Brand ($itembrand)’ so to reference the brand in a rule, we need to use the reference $itembrand. We know that we want to use an IF statement, that’s formatted as:
IF(conditional statement, true return, false return)
So, the conditional statement we’re interested in is if the brand name is “Acme Co.” If it is, then the true return would be “Acme” and if not, the false return is the brand. Putting this into the rule, we generally have:
IF(brand is “Acme Co.”, “Acme”, brand)
We know that brand can be referenced as $itembrand, so taking this a step further, we have:
IF($itembrand=”Acme Co.”, “Acme”, $itembrand)
This is how it all looks in the Editor (click to enlarge):
We gave the rule a good name and description so we’ll remember what the rule does in the future and where we intend to use it. We also have the rule expression in the Editor.
Notice how the Editor uses different colors for different parts of the rule. Purple is used for functions, blue for field references, and strings are in red. If your cursor is next to a parenthesis, it will highlight the corresponding opening or closing parenthesis in green or will be red to indicate that there isn’t a corresponding one.
These colors are a good indication that you’re writing the rule correctly. Please also note that the preview will show errors in the rule, for example, if I typed “$itembrad” instead of “$itembrand” it would indicate it as an error in the preview (click to enlarge):
Once a rule is created and saved, you need to still map it to the marketplace or inventory template before it’s applied. To do this, open the template in question and click on the field to map it. Select the ‘Business Rule’ button and search for the rule you created. Select it and then click ‘Done’ and save the template changes.
On the next sync to the marketplace, your items will update to send the business rule output values.
Business rules are a great way to help optimize your business. Hopefully, you’re a bit more familiar with them now. In upcoming blog posts, we’ll explore additional functions, as well as how to combine multiple functions into one rule.
Things to Consider
While business rules are powerful, it’s important to remember that they have their limits. Rules can only work on a single SKU at a time, so they can’t compare values across SKUs, even ones in the same variation. It may sound obvious, but keep in mind that rules can’t read your mind. In order to write a business rule, you need to be able to define which criteria need to be used for all of your items. If you find yourself coming up with too many exceptions or your data input isn’t consistent, it might be better to create a new attribute to store your data.
If you want to learn more and can’t wait two weeks for our next blog post, feel free to explore more about business rules on our SSC and if you’re struggling with a rule, you can always open a case with support to assist you.