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”);‘post’, ‘http://localhost/WebService1/Service1.asmx/HelloWorld’, false);


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



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.


  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


  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.


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

      Nishant Rana


  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?



Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.