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)

Call webservice from javascript in CRM

(0) ShareShare
ReportReport
Posted on by

How to call a webservice from javascript in CRM ?please explain the steps with scenario.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Joe Gill Profile Picture
    on at

    Here is an example using Javascript mahenderpal.wordpress.com/.../calling-external-webservice-using-js

    However usin jquery may be easier spring.io/.../consuming-rest-jquery

    hth

    Joe

  • sandeepstw Profile Picture
    4,601 on at

    Hi Michel,

    Using CRM web resource you can call OData services using Ajax call.

    Odata query reference link : msdn.microsoft.com/.../gg309461(v=crm.7).aspx  

    Ajax call reference link:

    guruprasadcrm.blogspot.in/.../update-optionset-lookup-data-using.html

    Thanks,

    Sandeep

  • Community Member Profile Picture
    on at

    Thank you.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Michel,

        You can use an XMLHttpRequest with OData to call the CRM webservice endpoint. I've used the following javascript function to retrieve a record in CRM:

    function RetrieveRecord(id, entityType, select, expand, sCallback, eCallback) {
    	var sURL = Xrm.Page.context.getClientUrl();
    
    	// Make sure the trailing / is there
    	if (sURL.charAt(sURL.length - 1) != '/')
    		sURL += '/';
    
    	var _ODataPath = sURL + "XRMServices/2011/OrganizationData.svc/";
    	var systemQueryOptions = "";
    
    	if (select != null || expand != null) {
    		systemQueryOptions = "?";
    
    		if (select != null) {
    			var selectString = "$select=" + select;
    			systemQueryOptions = systemQueryOptions + selectString;
    		}
    
    		if (expand != null) {
    			systemQueryOptions = systemQueryOptions + "&$expand=" + expand;
    		}
    	}
    
    	var url = _ODataPath + entityType + "Set(guid'" + id + "')" + systemQueryOptions;
    
    	//alert(url);
    	var req = new XMLHttpRequest();
    	req.open("GET", url, true);
    	req.setRequestHeader("Accept", "application/json");
    	req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    	req.onreadystatechange = function () {
    		if (this.readyState == 4) {
    			if (this.status == 200) {
    				var retrieved = JSON.parse(this.responseText).d;
    // Do something } else { if(eCallback != null) eCallback(req.statusText); } } } req.send(); }

    Hope that helps.

    John

  • Community Member Profile Picture
    on at

    thanks john

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