USD to EURO conversion using transform map script for Import set API

kaduapoorva
Tera Contributor

I have a target table field (budget_cost) and source table field (u_budgetvalue) and i want to convert amount coming from third party using import set API and for that am using transform map, please suggest a correct script for currency (USD to EURO) conversion 

4 REPLIES 4

SP22
Mega Sage
Mega Sage

Hi @kaduapoorva,

can you please use onBefore transform script and let me know whether it is useful or not.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

// Add your code here
// Assume the conversion rate from USD to EUR is 0.85 (you should fetch this dynamically for accuracy)
var conversionRate = 0.85;

// Fetch the source field value (u_budgetvalue) which is in USD
var budgetValueInUSD = source.u_budgetvalue;

// Convert the USD value to EURO
var budgetValueInEUR = budgetValueInUSD * conversionRate;

// Assign the converted value to the target field (budget_cost)
target.budget_cost = budgetValueInEUR;
})(source, map, log, target);


Thanks
SP

kaduapoorva
Tera Contributor

Hello SP,

I have below concerns can you please help with updated code by considering below points 

1) With above code am unable to get the converted amount from source table to target table. It is taking same amount which am sending in REST API explorer 

2) For currency updates, am using fx_rate table where daily currencies are getting updated so we don't need to give fix conversion rate.

 

Thanks,

Apoorva

Jack Littlewort
Giga Guru

You will need to connect to some kind of API to fetch the current conversion rate. This may work for example: open.er-api.com/v6/latest/USD

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @kaduapoorva ,

Please check out this 2 below linbks which will be helpful.

We have OOB table the currency conversion is stored fx_rate with it you can solve your problem.

Also you can use the OOB API  var conv = new sn_currency.GlideCurrencyConverter()

https://www.servicenow.com/community/grc-forum/rate-conversion-table/m-p/2447689

https://www.servicenow.com/community/developer-forum/currency-conversion-to-usd/m-p/1866905

 

Thank you,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.