Fetch exchange rates from the Web in AX:

Hi,
To fetch exchange rates from the Web in AX:

Below code is useful to get exchange rates for the current company currency(where currency codes are selected from the currency table).

static void GetExchangeRates(Args _args)
{
com com = new com(‘microsoft.xmlhttp’);
com com1;
XMLDocument xmlDoc;
Dialog exchDialog = new Dialog(“Exchange Rates”);
DialogField fromField;
DialogField ToField;
str url;
;

fromField = exchDialog.addField(typeid(currencycode), ‘Base Currency’);
fromField.value(CompanyInfo::find().CurrencyCode);
ToField = exchDialog.addField(typeid(currencycode), ‘To Currency’);
if(exchDialog.run())
{
url = “http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?”;
url += “FromCurrency=” +strupr(fromField.value())+”&ToCurrency=”+strupr(ToField.value());
com.open(“get”,url, false);
com.send();
com1 = com.responsexml();
xmlDoc = XmlDocument::newXml(com1.xml());
info(“1″+fromField.value() + ” = ” +xmlDoc.getNamedElement(‘double’).text() + ” ” +ToField.value());
}
}

Below code is useful to get exchange rates for the current company currency(where any currency code can be selected based on the ISO currency code).

static void GetExchangeRates(Args _args)
{
com com = new com(‘microsoft.xmlhttp’);
com com1;
XMLDocument xmlDoc;
Dialog exchDialog = new Dialog(“Exchange Rates”);
DialogField fromField;
DialogField ToField;
str url;
;

fromField = exchDialog.addField(Types::String, ‘Base Currency’);
fromField.value(CompanyInfo::find().CurrencyCode);
ToField = exchDialog.addField(Types::String, ‘To Currency’);
if(exchDialog.run())
{
url = “http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?”;
url += “FromCurrency=” +strupr(fromField.value())+”&ToCurrency=”+strupr(ToField.value());
com.open(“get”,url, false);
com.send();
com1 = com.responsexml();
xmlDoc = XmlDocument::newXml(com1.xml());
info(“1″+fromField.value() + ” = ” +xmlDoc.getNamedElement(‘double’).text() + ” ” +ToField.value());
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s