Saturday, 16 November 2013

Detect browser in crm 2013

How to detect browser in CRM ?

Hello CRM Lovers,
          Here is my findings, In this post i will share with you how to detect browser in CRM. It is not a big task, easy one.

I can understand the CRM developers requirements, because after release of CRM roll up 12 and CRM 2013, we can access CRM on cross browsers also. when we did customization with java script functionality, It may vary browser to browser, so there may be need of browser detection in CRM 2011 and in CRM 2013. So here is the simple java script code for CRM and it will work in CRM 2011(rollup 12) as well as in CRM 2013.

Add the fallowing code to your crm java script web resource.

         Mscrm.Utilities.isIE = function() {
             return Sys.Browser.agent === Sys.Browser.InternetExplorer

         function detectBrowser() {
            if (Mscrm.Utilities.isIE()) {
               alert("You are using IE");
             if (Mscrm.Utilities.isFirefox()) {
               alert("You are using Firefox");
            if (Mscrm.Utilities.isChrome()) {
               alert("You are using Chrome");

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 

Tuesday, 5 November 2013

Retrieve data in crm 2013

Replacement of SOAP in CRM for retrieve data with java script.

Hello CRM Lovers,
    First of all thanks for reading my post. As we all know that after CRM Roll-Up 12, SOAP has stopped working for cross browser support in CRM, so we have to write some other code to solve this problem. I found a way to solve this problem so I am sharing it with the beautiful world.
    In this post I am going to describe how to retrieve data with java script of another entity in CRM 2011, CRM 2013 with JSON and OData.It will work on Roll-Up 12, Roll-Up 13 for CRM 2011 and on CRM 2013, and also in cross browsers. It will really help you. For retrieving data please fallow these steps.

  Retrieving Multiple Records with ODATA in CRM with Java Script

  Java script for retrieving data in cross browser

Step 1:-  First of all you have to add this function in your web resource.

 //*******Retrive Multiple recored on the basis of the criteria OData Rest //******************************************************************************************

function retrieveMultiple(odataSetName, filter, successCallback, errorCallback, _executionObj) {
    _executionObjMultiretrive = _executionObj;
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    //odataSetName is required, i.e. "AccountSet"  
    if (!odataSetName) {
        alert("odataSetName is required.");
    //Build the URI 
    var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName;
    //If a filter is supplied, append it to the OData URI
    if (filter) {
        odataUri += filter;
    //Asynchronous AJAX function to Retrieve CRM records using OData
        type: "GET",
        async: false,
        contentType: "application/json; charset=utf-8",
        datatype: "json", url: odataUri,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        success: function (data, textStatus, XmlHttpRequest) {
            if (successCallback) {
                if (data && data.d && data.d.results) {
                    successCallback(data.d.results, textStatus, XmlHttpRequest);
                else if (data && data.d) {
                    successCallback(data.d, textStatus, XmlHttpRequest);
                else {
                    successCallback(data, textStatus, XmlHttpRequest);
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (errorCallback)
                errorCallback(XmlHttpRequest, textStatus, errorThrown);
                errorHandler(XmlHttpRequest, textStatus, errorThrown);
function errorHandler(xmlHttpRequest, textStatus, errorThrow) {
    alert("Error : " + textStatus + ": " + xmlHttpRequest.statusText);

Step 2 :-  Now add the fallowing functions with your custom code. Suppose you want to retrieve all the records from a entity which has single line text attribute and its value = "multiple retrieve with odata". for this condition you can use this code.

//**********************************************************************************//*****************Your custom function for retrieving data********************
    function YourFunction() {
        var _condition= "multiple retrieve with odata";
       if (_condition!= null) {
             retrieveMultiple("Entity NameSet", "?$filter=Attribute Schema Name eq '"+_condition+"' ", RetrieveEntityRecords, null, null);


    function RetrieveEntityRecords(data, textStatus, XmlHttpRequest) {
      if (data.length > 0) {
             for (i = 0; i < data.length; i++) {
                var attribute1 = data[i].attribute1 schema name;
                var attribute2 = data[i].attribute2 schema name;

Here  "data" is object of all retrieved records, you can find  your required attribute accordingly.

I know your condition may be differ.

The filter condition differs on the basis of attribute type so you can visit this link for more conditions...

Or you can download odata query designer from this link from here you will get a managed solution import it in your organization and design your odata query according to your requirement.

So by fallowing all upper steps you can retrieve records . It will work in cross browser and in all new Roll-Up 12,Roll-Up 13 . 

Enjoy the great technology Dynamics CRM. Good luck.....!!!!!