Write, Bureaucrats, Administrators
4,332
edits
mNo edit summary |
mNo edit summary |
||
Line 336: | Line 336: | ||
The user will enter the value in PriceUSD and the value in Euros will appear in PriceEUR according to the current exchange rate. | The user will enter the value in PriceUSD and the value in Euros will appear in PriceEUR according to the current exchange rate. | ||
We will create a Trigger on Event '''Create entry to Add''' and | We will create a Trigger on Event '''Create an entry to Add''' and Phase '''After saving the entry'''. | ||
<source lang="javascript"> | <source lang="javascript"> | ||
result = http().get("http://api.fixer.io/latest?base=USD") | result = http().get("http://api.fixer.io/latest?base=USD"); // Use http://fixer.io/ for | ||
// conversion rate in JSON | |||
usdToEur = JSON.parse(result.body)["rates"]["Eur"] | usdToEur = JSON.parse(result.body)["rates"]["Eur"]; // Use JavaScript object JSON | ||
// to parse the result | |||
entry().set("PriceEUR" , entry().field( "PriceUSD") * usdToEur ) // | entry().set("PriceEUR", | ||
entry().field( "PriceUSD") * usdToEur ); // PriceUSD * conversion rate | |||
// for value for PriceEUR | |||
</source> | </source> | ||