web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

I am new to WebServices.I want to call external currency converter WebService using JavaScript Onchange Event

(0) ShareShare
ReportReport
Posted on by 195

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();7823.abc.png

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    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:

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/walkthrough-write-your-first-client-script 

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/events/attribute-onchange 

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/controls/getattribute 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans