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.