## Introduction

Template functions can be used to program the template output through writing functions in the “Format” text box of Field properties dialog box. For example:

> You can write specific text for specific product families by detecting their parents products,

> You can do calculate and add tax to product price

> You can do “IF” checks and format the output accordingly

> You can take “Not” of a boolean and perform some action

## Programming guidelines

There are 3 types of parameters and all multiple statements must be separated with “dot” (.).

E.g.: Product.Price, Product.Price.Multiply(1.2).Then ()

## Strings and Text

Strings are regular text that goes into the expression without any change.

E.g.: Description, or Sales

## Dynamic Variable, Fields

Fields are data sources from your inventory database, and each product has all these fields assigned. Below are Dynamic Fields syntax and guidelines:

> Some products may not have values for these fields, these are assigned as “**NULL**”.

> Some fields are boolean, meaning only have 2 possible values; “**TRUE**” or “**FALSE**”.

> Some fields may be number or text specific

> All fields must be put in **curly brackets** when being referred to, e.g:** {Product.Price} **

## Functions

Functions perform checks and run operations to dynamic Variables. Below are some function writing guidelines:

> All functions must be put in **Curly brackets {} **or the system won’t recognize the text as a function. E.g.: **{**Add(10)**}**

> Once a Curly bracket is opened (**{**), you can write functions as many as you want; just make sure to separate them with a dot **(.). **E.g.: If({Product**.**Price**.**GreaterThan(100)},expensive,cheap)

> You don’t need to open multiple curly brackets when you are already in one.

> When the function is written make sure to Close the Curly brackets (**}**).

> General function syntax is writing the function name and open/close parenthesis “**()”** with some value in it.

> Some functions don’t require paranthesis, below is a list of those functions:

** >> Space prints a space character (“ ”),**** **

** >> EmptyStr prints empty string (“”),**

** >>** **NewLine** prints a new line (“<CR, LF>”),

** >> IsNull** checks if the value is null or not,

** >>** **IsTrue** checks if the function returns true or not.

E.g.: **{**Product.Price.GreaterThan(100).Then(NewLine)**}**

Here ”Product.Price” Field, and both “GreaterThan” and “Then” function were put in curly brackets and all were separated with a Dot **(.)**; even though there were two functions and a field, only one set of Curly brackets were used.

**Math Functions**

**Math Functions**

StoreAutomator has built in math functions to do basic calculations in statements. Math Functions always perform operations on the value on the left hand side with the value in brackets.

Below is a list of these functions that might be useful in some cases:

** >> ****Add()**, e.g: {Product.Price.Add(10)}, or {Price.Add(-10)},

** >> Multiply(),** e.g: {Product.Price.Multiply(1.2)},

** >> Divide(), **e.g: {Product.Price.Divide(2)},

** >> Percent(), **e.g: {Product.Price.Percent(80)}

Multiple Math functions can be performed in a line separated by dots (**.**):

E.g: {Product.Price.Multiply(1.2).Add(10).Divide(2).Percent(90)}

Can be written as a Math expression as: (((Product.Price X 1.2 ) + 10 ) / 2 ) X 90 /100

**If() Function**

You can use “**If()”** statement to do checks and then perform actions. Basic usage is:

**If(Comparison_Statement, **

**Then**[Statements_to_be_executed_if_Comparison_statement_is_TRUE],

**Else**[Statements_to_be_executed_if_Comparison_statement_is_FALSE])

Or in short: ** If(Comparison_Statement, Then, Else)**

Here “Then” expression is required, “Else” is not required.

Basic Usage Example:

If({Product.Price.GreaterThan(100)},expensive,cheap)

Result: If this particular product’s “Price” Field value is greater than 100, then it will display “expensive”, and if the field’s value is not greater than 100, then it will display “cheap”. “GreaterThan” is a **Comparison Operator** and it results in either “TRUE” or “FALSE” value; “TRUE” executes the action written after the first comma (,) and “FALSE” executes the action, which is written after the second comma.

**Comparison Operators** always compares the value on its left hand side with the value in brackets. If we look into the example above, “**GreaterThan**” is the comparison operator and comparing the values of **Product.Price **and **100**.

Below is a list of all comparison operators in Store Automator:

** >> GreaterThan()** – Checks if the value in left hand side is greater than the value in brackets,

** >> GreaterThanOrEqualsTo()** – Checks if the value in left hand side is greater than or equal to the value in brackets,

** >> LessThan()** – Checks if the value in left hand side is less than the value in brackets,

** >> LessThanOrEqualsTo()** – Checks if the value in left hand side is less than or equal to the value in brackets,

** >> EqualsTo()** – Checks Equality of the value in left hand side and the value in brackets.

“If” statement cannot nest multiple conditions in its brackets, to nest multiple conditions, please use **Then** function.

“If” statement can be used with Boolean functions and boolean fields. Boolean functions can return only two values, either “**TRUE**” or “**FALSE**”.

E.g.:

If({Product.Name.IsNull},Product does not have a name,Product has a name)

Result: “IsNull” function checks if the Product’s Name in Null or not. If the function returns “True” (Meaning, yes, it is Null, this product don’t have a name) then it will display “Product do not have a name”, if the result is “FALSE” then it will display “Product has a name” on the screen.Boolean Functions returns the result; returns TRUE, if the result is TRUE and FALSE if the result is FALSE.

Below is a list of Boolean Functions in StoreAutomator:

** >> IsNull **– Checks if the field is *NULL,*

** >> IsTrue** – Checks if the function being checked returns *TRUE,*or the value of the field being checked is *TRUE,*

* >> StartsWith() – Checks if field starts with the expression in brackets,*

Boolean fields can have “**TRUE**” or “**FALSE**” value, also.

E.g.:

If({Product.IsInStock},We have this product,We do not have this Product)

Result: If this particular product’s “IsInStock” field has a value of “TRUE” then it will display “We have this Product”, if the field is “FALSE” then it will display “We do not have this Product” on the screen. Below is a list of Boolean Fields in StoreAutomator:

** >> IsFba** **–** Checks if the Product’s “IsFba” field is TRUE

** >> IsFreeShipping ****–** Checks if the Product’s “IsFreeshipping” field is TRUE

** >> IsInStock ****–** Checks if the Product’s “IsInStock” field is TRUE

** >> IsLowStock ****–** Checks if the Product’s “IsLowStock” field is TRUE

** >> IsNew ****–** Checks if the Product’s “IsNew” field is TRUE

** >> IsOnSale ****–** Checks if the Product’s “IsOnSal”e field is TRUE

** >> Discontinued ****–** Checks if the Product’s “Discontinued” field is TRUE

** >> FastListingEnabled ****–** Checks if the Product’s “FastListingEnabled” field is TRUE

StoreAutomator recognizes the following values as **FALSE**:

>> **NULL** character,

>> If the field is a number type field, the number Zero (0), (all other numbers return True),

>> If the field is a string type field, empty string(“”), (all other characters return True).

**Then Function**

**Then Function**

Then Function checks the condition written on the left-hand side and executes the statement in brackets. Basic usage is:

Condition_Statement**.Then(Then,Else)**

Condition Statement is checked and, if returned “True” then the system executes the code in the first part of the brackets (Then part), if returned “False” then the system executes the code in the second part of the brackets (Else Part). Similar to **IF() **function**,** **Then** part is required and **Else** is not.

E.g.:

{Product.Sku.StartsWith(FBA-CAN).Then({Product.FbaFee},0)}

Result: Function checks if the Product.SKU starts with “FBA-CAN”, if returned “True” then Product’s FbaFee Value is written on the screen, if returned “False” then “0” is written.

Multiple statements can be logically checked using **And** or **Or** functions which are written before “Then” and the statement in brackets will be executed. E.g.:

Condition_1.**And**(Condition_2).**And**(Condition_3).**Then**(then, else)

Condition_1.**Or**(Condition_2).**OR**(Condition_3).**Then**(then, else)

**Other Logical Operators**

**Other Logical Operators**

*Not() *

*Not()*

Not, takes the inverse of a boolean value, Basic Usage is:

**Not(Field_Value)**

**Not (Boolean_Function)**

E.g.: {Not(Product.IsOnSale).Then(Product is not on sale)}

Result: If the Product is **not** actually on sale, so IsOnSale value = False, taking NOT of False is TRUE, so the condition becomes TRUE and then function will perform the action after “Then”, and display “Product is not on sale” on screen; If the Product is actually on sale(Not of IsOnSale=FALSE), then Do nothing; “Then” function doesn’t require the second part.

**Any() **

**Any()**

Any checks if, are there any fields having a value as “True” is a list. Any, returns TRUE if at least one variable in the list is “TRUE” and the rest have value ”False”. Basic Usage is:

**Any(Value_a,Value_b,Value_c,…)**

E.g.:

{Any(Product.IsInStock,Product.IsNew, Product.IsOnSale)}

Result: Let’s say these fields have the following values:

IsInStock= True

IsNew= False

IsOnSale= False

There is one True value, so the result will be “True”

**All()**

**All()**

All checks if all values being “True” or not, in a list. All returns “False”, even if there is just one “False” and the rest have a value of “True”, in the list is. Basic Usage is:

**All(Value_a,Value_b,Value_c,…)**

Considering the above example given for “Any”:

There are two “False” values, so the result will be “False”

Let’s say these fields have the following value:

IsInStock= True

IsNew= True

IsOnSale= True

All Values are True, so the result will be “True”

**And()**

**And()**

And function performs logical AND between all values. Basic usage:

{Field_Value1.**And**({Field_Value1}).**And**({Field_Value2}).**And**({Field_Value3})…

Let’s use the same fields from above example:

{Product.IsNew.And({Product.IsInStock}).And({Product.IsOnSale})}

Result: Values of below fields taken from above:

IsInStock= True

IsNew= False

IsOnSale= False

AND of these values will be “False”

**Or()**

**Or()**

Or Function performs logical OR for all objects in a list. Basic usage:

{Field_Value1.**Or**({Field_Value1}).**Or**({Field_Value2}).**Or**({Field_Value3})…

Let’s use the same fields from the above example:

{Product.IsNew.Or({Product.IsInStock}).Or({Product.IsOnSale})}

Result: Values of below fields taken from above:

IsInStock= True

IsNew= False

IsOnSale= False

Or of these values will be “True”

**Count**

**Count**

Count function counts the number of objects in a list. Basic usage:

Field_Variable.**Count**

E.g.:

Product.Url.Count

Result: Code counts the number of characters in the Url field and returns the number.

**Sum**

**Sum**

Sum function adds all objects value together. It is similar to add function. Sum operates on values on right-hand side, while Add adds two values, one left-hand side and one in right-hand side brackets. Basic usage:

**Sum(**Field_1, Field_2, Field_3,…**)**

E.g.:

Sum({Product.Quantity},{Product.SaleCount})

This adds these two fields value together and returns.

**Negate**

**Negate**

Negate function take the inverse of the value, it is similar to Not operator. Negate operates on the left-hand side value, while NOT operates on the value in the brackets on the right hand side. Basic usage:

Field.**Negate**

E.g.:

IsFba.Negate:

Let’s say IsFba = False

Result will be: True

**Examples:**

Product.Price.Add({Product.Sku.StartsWith(FBA-CAN).Then({Product.FbaFee},0)})

To make FBA Fee work you should mark your product as FBA. Then the system collects FBA fees for that product. FbaFee in our system refers to TotalFbaFees-ReferralFee.

If you mark your products as FBA then that statement simply becomes

Product.Price.Add({Product.IsFba.Then({Product.FbaFee},0)})

If({Product.Cost.Multiply(1.5).Add({Product.ShipCost}).LessThan({Product.Msrp})},{Product.Msrp},{Product.Cost.Multiply(1.5).Add({Product.ShipCost})})

#### E.g. Detecting a products Parentage

– To detect the product’s parentage use: Product.IsParent

This will return True or False. True being The product is parent

– StoreAutomator has three product properties for this. IsParent, IsChild and IsSingle. You can use like below:

If(Product.IsParent, parent, noparent)

or there is another form you can use, which might be more readable

Product.IsParent.Then(parent,noparent)