The Feed Doctor on Context
This week, L. in “Woostah,” MA, writes:
Dear Feed Doctor,
Can I write a business rule that does one thing when used in a template for one shopping provider, but does something completely different for all the rest?
You sure can. It’s unlikely you’d ever need to, since you can create different rules for each provider, but it’s good to know you could if you had to.
GETCONTEXTVALUE
There’s a special function called GETCONTEXTVALUE that will return different output depending on how your account is setup, which provider your feed is for, or even the number of items currently processed. For convenience, let’s call these, oh, “context values.” GETCONTEXTVALUE has only one parameter: the name of the context value you want. Here are some particularly useful ones:
- CurrencyCode. This value depends on your account setup. For US accounts, the return value is “USD.”
- CurrentExportCount. This is the number of items that have been successfully added to the output feed. The return value is 0 for the first item (because there aren’t any in the feed yet, see?), 1 for the second, and so on.
- SiteCode. This is a text value that identifies the shopping provider that the output feed is destined for. Usually it’s just the name of the provider as we show it in our UI, but with certain characters, such as spaces, removed
So how would you use these? Well, as it turns out, some of our default templates use the first two. Some providers require the currency code in their feeds, and some want the feed’s total item count in either the header or footer; calling GETCONTEXTVALUE("CurrentExportCount") at the end of processing will return this, so we create these headers and footers last. You could also use GETCONTEXTVALUE("CurrentExportCount") in the item part of the template if you needed to do something like give each item a unique number, or you could write a filter that limited your feed to the first 100 items, etc. And finally, here’s the answer to L’s question:
IF(GETCONTEXTVALUE("SiteCode")="SomeProvider","Do One Thing","Do Another")
