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
thank you for your submit
LikeLike
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
LikeLike
Hi, Thanks for your comment!!
To pass parameters to the web service call check this post of mine
https://nishantrana.wordpress.com/2009/01/24/understanding-and-using-ajax/
LikeLike
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.
LikeLike
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
LikeLike
Check this url
https://nishantrana.wordpress.com/2008/08/13/consuming-an-aspnet-web-service-using-soap-protocol-from-javascript/
LikeLike
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
LikeLike
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.
LikeLike