When / then

One of the primary constructs in the DropStream 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, when an order with the following block of code

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

passes through the rule engine, the 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 part 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”
end

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 "in the scope" of add.

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

Comments

0 comments

Please sign in to leave a comment.