I have been very busy planning for our next release and I have to say, I am very excited about what we are doing next! More on that later........... I am still getting mail from folks asking how to access a web service from CRM forms. I thought I share a little JScript code that I used for some of my demos. This code accesses a public web service to get the exchange rate between US$ and a given currency. I did a MSN search and found a public web service; webservicex.net; that provides a public currency converter web service. Then I added one picklist and two fields to the Invoice Business Entity using the Customization tools in CRM V3.0: fabrikam_exchangerate (shows the exchange rate) and fabrikam_totalcurrency (shows the total amount in the selected currency).
Here is the code followed by a snapshot of the Customized CRM Invoice form. You can easily copy and paste this code into your OnChange, OnSave or OnLoad form event using the CRM V3.0 form editor. I added the code as an OnChange event to a new picklist (target currency) that I added earlier to the form.
// Declaring Some variable here including the web service to connect to
var
//This is my picklist. I have already added three currency that i want to support the exchange to
switch
{
case 1: i = "JPY"; break; case 2: i = "GBP"; break; case 3: i = "EUR"; break;
case 1:
i = "JPY";
break;
case 2:
i = "GBP";
case 3:
i = "EUR";
}
//Instantiating connection to the web service and calling the get method
xmlhttp.open("get", serverUrl + "/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency="+escape(i), false);
xmlhttp.send();
//Parsing the returned XML
valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd) + startTag.length;
valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);
exch = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);
//Setting the Exchange rate on the custom attribute that i have added for this purpose earlier
crmForm.all.fabrikam_exchangerate.DataValue = parseFloat (exch);
j = crmForm.all.totalamount.DataValue;
//Calculating and setting the total sum in the selected currency
crmForm.all.fabrikam_totalcurrency.DataValue = kk;
Hello JScript friends, I'm back from vacation and back again to enjoy some interesting jscript stuff
OK, this is great, and it appears to be the sample code that is found in the Microsoft CRM SDK documentation.
I've written a custom web service in VS 2005 that I wish to call in the same manner from a CRM form. The form captures an integer field and needs to pass it to the web service, which validates it against another table, and return a true/false.
I don't believe one can pass the function name and the parameters to a SOAP web service using the URL syntax that you include in the sample code, above. At least not in the default manner that VS 2005 creates web services.
What needs to be done in order to get the full XML SOAP request structure into the call to the web service? What am I missing here?
My apologies in not getting this up sooner. I flew home on the red-eye on Wednesday night, drove from
This code solved alot of our problems. Thank you very much
PingBack from http://paidsurveyshub.info/story.php?title=arash-ghanaie-sichanie-blog-accessing-web-services-from-crm-forms