Triggers: Difference between revisions

204 bytes added ,  6 October 2016
m
no edit summary
mNo edit summary
mNo edit summary
Line 337: Line 337:


<source lang="javascript" line>
<source lang="javascript" line>
result = http().get("http://api.fixer.io/latest?base=USD")      // Use service http://fixer.io/ to get conversion rate in JSON format
result = http().get("http://api.fixer.io/latest?base=USD")      // Use service http://fixer.io/
usdToEur = JSON.parse(result.body)["rates"]["Eur"]              // Use standard JavaScript object JSON to parse the result
                                                                // to get conversion rate in JSON format
entry().set("PriceEUR" , entry().field( "PriceUSD") * usdToEur ) // Multiply PriceUSD by the conversion rate to determine the value for PriceEUR
usdToEur = JSON.parse(result.body)["rates"]["Eur"]              // Use standard JavaScript object JSON
                                                                // to parse the result
entry().set("PriceEUR" , entry().field( "PriceUSD") * usdToEur ) // Multiply PriceUSD by the conversion rate
                                                                // to determine the value for PriceEUR
</source>
</source>