Calling Asp.NET web service from form onLoad in CRM

This is the code we can make use for calling ASP.NET webservice in form onLoad javascript event handler of our Entity in Microsoft CRM.

This example calls the simple Hello World service and assigns the value returned (i.e. “Hello World”) to a field in the entity form

xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);

xmlHttp.open(‘post’, ‘http://localhost/WebService1/Service1.asmx/HelloWorld’, false);

xmlHttp.send();

var xmlDoc=xmlHttp.responseXML;

var responseElement=xmlDoc.getElementsByTagName(“string”)[0];

var exch=responseElement.firstChild.nodeValue;

crmForm.all.address1_name.DataValue=exch ;

return false;

Check this link for more information

https://nishantrana.wordpress.com/2007/10/18/calling-aspnet-webservice-from-javascript-ajax/

Bye


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

9 thoughts on “Calling Asp.NET web service from form onLoad in CRM”

  1. Hi, This doesn’t work for me. It doesn’t give any error when the form loads. But it gives the error message when I close the form.

    Like

  2. Dear Nishant,
    Thank you for you prompt reply,
    for more clarification, let us say the [WebMethod] “HelloWorld” takes as parameter an instance of some class instead of a string. How Can i pass this parameter from within the javascript CRM form?
    Thank you

    Like

  3. Dear Nishant,
    i know the post is old but i was searching to find out if i can call a webservice Method that takes instances of classes as parameters from JavaScript code on load event in CRM 4.0.
    how can i set it?
    xmlHttp.send(“instance of the class”)???

    Thank you.

    Like

    1. Hi Charles,
      In that case you would be sending Soap messages.
      You could check the format of the soap message for an asp.net web service method in its IE test page.

      Regards,
      Nishant Rana

      Like

  4. Thanks for the post, it was very helpful.

    How do you pass parameters to your web Method in this script context? In other words, f your ‘Hello world’ was taking a parameter, how do you do it?

    Thanks

    Like

Share your thoughts

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