When / then

One of the primary constructs in the PackageBee rule syntax is when/then for checking a condition. This construct is represented as an IF-THEN construct in PackageBee's GUI Editor and works like a programming language if-then statement that evaluates whether an expression is true, and if it is, does something.

For example, consider the following rule:

      order_item.sku is "My-Order"
      add 1.0 item to order_items in order
        set item.sku to "You-got-a-gift"

when an order is processed by PackageBee, the rules engine will search for a particular SKU called “My-Order”. If such an item is found, i.e., the condition after when evaluates to true, then the then block will be executed, and a new order item with an SKU "You-got-a-gift", will be added to the order.

A when/then-construct ends with an end keyword.

Note: add statements also include an end, as illustrated by the following code snippet:

add X item to order_items in order
  set item.sku to “string”

Note: A common mistake that can occur while adding an item, is using order_item.sku or order_items.skuin the set command, instead of item.sku. Here item in the add statement is a variable that is declared in the add command, so it should be used in the same form after set, which is "within the scope" of add.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.