Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

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

  • Suggested answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: I am new to WebServices.I want to call external currency converter WebService using JavaScript Onchange Event

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans