
Hi friends.I am new to webservices.I want to call external webservice using Javascript onchange event.I want to convert USD into INR.
This is the code I generated using RestBuilder
=======================================================================
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/trip_autocompletes()?$select=trip_inr", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var trip_inr = result["trip_inr"];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
*This post is locked for comments
I have the same question (0)Hello,
Your example looks like you're trying to call the Dynamics 365 Web Api, if you are calling an external webservice for your currency conversion (i.e. something other than the Dynamics 365 Web Api), you would have to consult the documentation of the external webservice, on how to call it with Javascript. The XMLHttpRequest will be involved but, it might not work the same as the Dynamics 365 Web Api
For the Dynamics 365 part, you can create a WebResource that contains your Javascript code and register it to the OnChange event of a specific field.
In Javascript you can call this code to read a field's value:
Xrm.Page.getAttribute("new_myfieldname").getValue()
For more on the Xrm framework for Javascript code in Dynamics 365, take a look at: