How tag rules work
Lesson 6 of 24 7 min read
Many Unleashed settings apply a value only to orders carrying a matching tag. Learn how tags, rules, data values and defaults fit together.
"Wholesale orders go in Parked." "Faire Direct orders belong to Mark." Rules like these depend on something about the individual order, and in Supply Lens that something is usually a tag. Around twenty of the Unleashed order settings are tag maps. Once you understand one, you understand them all. By the end of this lesson you will be able to read and write a tag rule.
What a tag is
A tag is a small label attached to a Document. Tags come from two places:
- The source Integration. When an Integration reads an order, it can tag the Document with facts about it. For example, a Faire order is tagged with where it came from, such as
faire:source:FAIRE_DIRECT, and a B2B Wave order with the customer's discount, such asb2b-wave:customer_discount_rate. - Mappings. A Mapping can add Target tags to the item it creates, so you can label everything that passes along a particular route.
A tag usually has up to three parts separated by colons: the source (which Integration wrote it), the key (what it describes) and the value.
Anatomy of a tag map
Here is the salesperson tag map from the settings guide:
"salesPersonTagMap": {
"items": [
{ "source": "faire", "key": "source", "value": "FAIRE_DIRECT", "data": "Mark Wallis" }
],
"default": "Will Harrald"
}
Read it as: if the order has a tag from faire whose key is source and whose value is FAIRE_DIRECT, use Mark Wallis; otherwise use Will Harrald.
| items | The list of rules. They are checked in order. |
|---|---|
| source | Which Integration wrote the tag. Leave it out to accept the tag whichever Integration wrote it. |
| key | What the tag describes, for example source or customer_discount_rate. |
| value | The tag value to match. In the salesperson map, values support * wildcards and regular expressions written between ^ and $. |
| data | The value to apply when the rule matches. Leave it out and the tag own value is used instead. |
| default | The value to apply when no rule matches. Leave it out and nothing is applied. |
Data versus the tag's own value
This is the part people miss. A rule can work in two ways:
- With
data: the rule pins a fixed value. "If tagged Faire Direct, the salesperson is Mark Wallis." - Without
data: the rule carries a value through from the tag. B2B Wave tags each order with the customer's discount rate, and this rule passes whatever rate it finds straight on:
"customerDiscountRateTagMap": {
"items": [
{ "source": "b2b-wave", "key": "customer_discount_rate" }
]
}
Defaults apply even with no tags
An entry with no matching tag still applies through the map's default. So if you want a blanket value for every order, you can set only the default and leave items empty. For example, customerDefaultsTagMap with just a default gives every new customer the same payment term and tax code.
A different shape: rules with tag and integration
A few settings use a slightly different rule shape. orderStatusMap rules have a tag (a partial match against the order's tags), an integrationKey (the source Integration, such as a Shopify store's key) and the orderStatus to apply. A rule needs at least one of tag or integrationKey, and if both are set, both must match. The first matching rule wins. You will meet it in the order status lesson.
Hilltop Coffee separates wholesale
Hilltop's café customers order through the same Shopify store as consumers. Priya wants to treat café orders differently, so Hilltop's Mapping from Shopify to Unleashed adds a target tag to café orders, and Priya's rules match on that tag. Before writing any rules, she opens a test Document in Supply Lens to check exactly how its tags appear, so her rules match the real thing.
Look before you write
Always open a real Document and read its tags before writing a rule. A rule that does not match exactly is silently skipped, and the default (or nothing) applies.
Recap
- Tags are labels on a Document, written by the source Integration or added by a Mapping.
- Tag map rules match on source, key and value, and are checked in order.
- A rule with
dataapplies a fixed value; withoutdatait passes the tag's own value through. - The
defaultapplies when nothing matches, so a map with only a default sets a blanket value. orderStatusMapusestagandintegrationKeyinstead, and the first match wins.
Quick guides for this topic
Your progress is saved in this browser. Create a free account to keep it everywhere, take quizzes and earn certificates.