PRESCRIBE
The PRESCRIBE function evaluates answer rules and returns items based on these rules.
Last updated
The PRESCRIBE function evaluates answer rules and returns items based on these rules.
Last updated
PRESCRIBE(table, [rowsSelector, colsSelector, condition, out])
Argument name
Description
table
Required
Table to evaluate containing the prescription rules. See below.
rowsSelector
Optional
Selector of rows. All rows by default.
colsSelector
Optional
Selector of columns. All columns by default.
condition
Optional
matchall Only adds an item if it is contained in all matching rows.
matchany (default) Adds an item if it is contained at least in a matching row.
out Optional
Also includes the results in a list.
Table syntax:
Column name
Description
answer
Required, Multiple
Answer rules to evaluate.
mode
Optional
include (default) Includes the items (if not excluded).
exclude Excludes the items.
weight
Optional
Assigns points to items that will be used to order them.
rule
Optional
Selects items based on attribute rules.
<other columns>
Required
Any other column is treated as items holder.
PRESCRIBE(mytable) If a1 is true, returns sku1 If a2 is true, returns sku2 and sku3 If a1 is true and a2 is true, returns sku1, sku2, sku3
PRESCRIBE(mytable) If a1 is true and a2 is true, returns sku3, sku1, sku2. Note sku3 is returned in the first place because it has more weight as it appears in two matching rules.
We can also use formulas that will be evaluated.
We can use multiple answer columns. In this case, answer columns in each row have to be evaluated as true for the rule to be met.
PRESCRIBE(mytable) If a1 is true and a2 is true, returns sku2 If a1 is true and a3 is true, returns sku1
PRESCRIBE(mytable) If health_bones is true and heath_sleep is true, returns sku2 and sku1. Note sku2 has more priority because of its assigned weight. If health_bones, heath_sleep, and allergy_fish are true, returns only sku2 because sku1 will be excluded according to rule 3.
PRESCRIBE(mytable, ':', ':', 'matchall') If a1, a2, and a3 are true, it returns sku2 because it is the unique item that appears in all matching rules according to the matchall condition. If a1, and a4 are true, it returns nothing because there are no items that appear in all matching rules.
PRESCRIBE(mytable, ':', ':', 'matchall') If a1 and a3 are true, it returns those products with tag cleanser that have size greater than 10. If a2 and a3 are true, it returns those products with tag serum or essential oil, that have size greater than 10.