Working with values

Altering values

You cannot simply add an integer to the return values, as they are returned as string values.

For example, with a current.price of 708.32, current.price + 100 returns a value of 708.32100.

You can use a parseFloat function in your script to provide the correct result. For example, parseFloat(current.price) + 100 will return 808.32.

Returning predictable values

Adding values to prices with scripts can be unpredictable. For example, consider a script which adds 100 to the price of our item.
var newPrice = parseFloat(current.price) + 100;

Running that script in the UK returns a value of var newPrice = parseFloat(708.32) + 100 = 808.32.

However, if you run it in the US, this returns a value of var newPrice = parseFloat(1000) + 100 = 1100.

To get the predictable values back into our item, regardless of the session under which the script runs, you can write your scripts to run in the system's base currency.

For example:
var newPrice = parseFloat(current.price.getReferenceValue()) + 100 ;
current.price
 = current.price.getReferenceCurrencyCode()
 + ';' + newPrice ; 
Note: This example still relies upon knowing what the base currency is, for the 100 to be meaningful.