Currency converter through in Dynamics CRM

To make currency convert into different country currencies in Dynamics CRM. I developed this below javascript.

 function convert(){
debugger;
// YOUR_APP_ID='API_KEY';
 $.ajax({
    url: 'https://openexchangerates.org/api/latest.json?app_id=API_KEY', 
    type: 'POST',
  success: function(data) {
        // exchange rata data is stored in json.quotes
        alert(data.rates.INR);
        // base currency is stored in json.base
        alert(data.base);
        // timestamp can be accessed in json.timestamp
        alert(data.timestamp);

var INR =data.rates.INR;
var USD = data.rates.USD;
var EURO= data.rates.INR;

var txtINR =Xrm.Page.getAttribute("new_inr").getValue();
var txtUSD =Xrm.Page.getAttribute("new_dollar").getValue();
var txtEURO = Xrm.Page.getAttribute("new_euro").getValue();
//from inr to usd and dollar
if(txtINR != null)
{
var val = parseFloat(txtINR).toFixed(2);
//INR to USD
var inrtousd = (1/INR)*val;
alert(inrtousd);
//INR to EURO
var inrtoeuro = (EURO/INR)*val;
alert(inrtoeuro);
break;
}
else if(txtUSD != null)
{
//from usd to inr,euro
var val1 = parseFloat(txtUSD).toFixed(2);
//USD to INR
var ustoinr = val1*INR;
alert(ustoinr);
//USD to EURO
var ustoeuro =val1*EURO;
alert(ustoeuro);
break;
}
else if(txtEURO !=null)
{
//from euro to inr,usd
var val2= parseFloat(txtEURO).toFixed(2);
//EURO TO INR
var eurotoinr = (INR/EURO)*val2;
alert(eurotoinr);
//EURO TO USD
var eurotousd(1/EURO)*val2;
alert(eurotousd);
break;
}
    }
  });
  }

No comments:

Post a Comment