CRM2011 JavaScript calls using CrmServiceToolkit SOAP Endpoint.

To be able to query the CRM2011 Web Services using de SOAP END POINT we need a SDK library called CrmServiceToolkit.js embebed in the page-form from where we want to make JavaScript queries.
I have attached the library as a .doc document (cause WordPress don’t allow to upload .js files). Please download it here and change the file extension to .js to be able to add it to you CRM2011 as a web resource. You will need as well the opensource jquery and json libraries.

As I explained before, the main different between this type of call and the ODATA rest endpoint calls is that they work as synchronous calls which means that after the query has been made, the JavaScript execution will stop running until the response has arrived.

Once you have the library in your form, we can make SOAP queries using this simple commands.

Retrieve Record

var contactId = '3210F2BC-1630-EB11-8AB1-0003AAA0123C';
var cols = ["firstname", "lastname", "birthdate", "email"];
var retrievedContact = CrmServiceToolkit.Retrieve("contact", contactId, cols);


Fetch Queries

var fetchXml = [   
"<fetch mapping='logical'>",   
   "<entity name='contact'>",   
	  "<attribute name='createdby' />",   
	   "<filter type='and'>",   
		 "<condition attribute='createdby' operator='eq-userid'/>",   
		 "<condition attribute='contactid' operator='eq' value='",crmForm.ObjectId, "' />",   
		"<condition attribute='createdon' operator='last-x-hours' value='1' />",   	

 var fetcheUsuario = CrmServiceToolkit.Fetch(fetchXml);

The only difficult thing here is creating the fetch command. But as you will probably know, using the CRM2011 Advance Find tools we can create queries as complex as we need an convert them to fetch XML with just one click.

Get fetch from Advance Find Tools

Get fetch from Advance Find Tools

Querying by Attributes

var queryOptions = {
   entityName : "contact",
   attributes : ["name", "contactid","surname","mainphone"],
   values : ["peter", "680","griffin","919191919"],
   columnSet : ["chm_idproducto_1"],
   orderby : ["surname"]

var fetchedContacts = CrmServiceToolkit.queryByAttribute(queryOptions);

Retrieve Multiple

var firstname = 'Hache';
var query = [].join("");

var retrievedContacts = CrmServiceToolkit.RetrieveMultiple(query);

Creating Records

var contactrecord = new CrmServiceToolkit.BusinessEntity("contact");
contactrecord.attributes["Name"] = "Peter";
contactrecord.attributes["SurName"] = "Griffing";
var createResponse = CrmServiceToolkit.Create(contactrecord);

Updating Records

ar contactId = '4D507FFE-ED25-447B-80DE-00AE3EB18B84';
var contact = new CrmServiceToolkit.BusinessEntity("contact");
contact.attributes["contactid"] = contactId;
contact.attributes["address1_line1"] = "45 green St.";


Deleting Records

var contactId = '3210F2BC-1630-EB11-8AB1-0003AAA0123C';
var deleteResponse = CrmServiceToolkit.Delete("contact", contactId);

And these are the most common functions that we can use using the CRMService SOAP EndPoint. Some of this info was found here.

If you want to get information about the CRM211 Odata queries REST END POINT just read my post about it.

As i explained in previos posts, SOAP Point querys are less efficient than Rest Point queries but more powerfull. With Rest we can not make service calls while with SOAP we can do it this way.

Service calls

var whoAmI = CrmServiceToolkit.Execute("");
currentUserId = whoAmI.getElementsByTagName("UserId")[0].childNodes[0].nodeValue;
alert("Current user's ID is " + currentUserId);

One thought on “CRM2011 JavaScript calls using CrmServiceToolkit SOAP Endpoint.

Leave a Reply

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

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