Working with JQuery and CRM 2011

For adding JQuery or any other Javascript library now so much easy with CRM Web Resources. you just have to follow the below steps:

1. Open your Solution or open the Default Solution by going to Settings > Custmoizations > Customize the System.
2. Select Web Resources and Click New.
3. Enter a name and Select Type: Script (JScript). I recomend also entering the JQuery file name in the descript so you know what version is installed.
4. Click Browse and Select the JQuery file you just downloaded.
Save and Publish the new Web Resource.

Playing around with JQuery and CRM oData Service you have to add mostly
1. JQuery
2. JSon2

Code Snippet:

How can you get the Account Name and Number using JQuery

function getAccountDetailsByAccountId) {
var entity = "Account";
var select = "?$select=AccountId,AccountNumber,Address1_Country,Address1_City,Name"
var oDataSelect = "/XRMServices/2011/OrganizationData.svc/" + entity + "Set(guid'" + accountId + "')" + select + "";

$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest) {
ProcessData(data.d);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
}
});
}

function ProcessData(accountEn) {
alert("Account Number: " + eval(accountEn.AccountNumber));
}

You will find more details about oData Service and Other Resources below:
http://msdn.microsoft.com/en-us/library/gg309461.aspx
http://jquery.com/
https://code.google.com/p/jquery-json/downloads/detail?name=jquery.json-...

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.