Tuesday, June 25, 2013

Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.

Today I tried to run Silverlight sample project in my machine and I got below error.
“Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.”

I checked the Silverlight version I installed and it was version 4. Then I just did a Google search and found the below blog post, after installing Silverlight_Developer.exe I was able to run Sample Silverlight application successfully. 



Thanks

Monday, June 24, 2013

CRM 2011 Filtered sub grid

Filtered sub grid is very commonly used feature in CRM 2011.
As you may already know we can use CRM default feature to filter sub grid data by selecting different views for sub grid. But you may come across situations where system needs to filter sub grid data based on opening record field,
For example you need to filter Contact sub grid based on Account form City field. So sub grid should only Contacts which have same city as Account City:
In this kind of scenario we can use javascript to add filter to the sub grid.

Use advance find and generate fetch xml for filter contact

function setContactSubGrid() {
    var grid = $('#accountContactsGrid')[0];
    var accountCity = Xrm.Page.getAttribute("address1_city").getValue();
    if (grid == null || grid.readyState != "complete") {
        setTimeout('setContactSubGrid()', 2000);
    }
    else {

        var fetchXml = "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "";
            
        grid.control.setParameter("fetchXml", fetchXml);

        grid.control.refresh();
    }
}
Call this function on Account onLoad event.

Sunday, June 23, 2013

How to Refresh a SubGrid in MS CRM 2011

Code snippet 1 :

function LoadSubGrid(SubGridName) {
    var grid = document.getElementById(SubGridName);
    if (grid) {
        if (grid.readyState == "complete") {
            grid.Refresh();
        }
    }
}
Code snippet 2 :

function LoadSubGrid(SubGridName) {
    var grid = Xrm.Page.ui.controls.get("SubGridName")
    if (grid) {
        if (grid.readyState == "complete") {
            grid.Refresh();
        }
    }
}

Friday, June 21, 2013

Using OData endpoint in MS CRM 2011

As most of you already know in CRM 2011 there are two ways which we can write client script to work with CRM Data.

  • SOAP endpoint: recommended for retrieving metadata, assigning records, executing messages 
  • REST endpoint: recommended for create, retrieve, delete and update, associating and disassociating records, 

Here I’m explaining one of the easiest ways to retrieve data using OData query designer.

Download Link OData Query designer: http://crm2011odatatool.codeplex.com/
For this example I’m getting Template Id by Name,
First Generate query using CRM 2011 OData Query Designer

 

function GetTemplateId() {

    var query = serverUrl + "xrmservices/2011/OrganizationData.svc/new_interventiontemplateSet?$select=new_interventiontemplateId&$filter=new_WebResourceName eq '" + webName + "'";
    var templateId;

    jQuery.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: query,
        async: false,
        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 (data && data.d != null) {
                templateId = data.d;
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert("Error :  has occured during retrieval of the Template");
        }
    });

    return templateId;
}
Update Record:
function Update(id, entityObject, odataSetName) {
        var jsonEntity = window.JSON.stringify(entityObject);
        var serverUrl = Xrm.Page.context.getServerUrl();

        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
        datatype: "json",
        data: jsonEntity,
        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
        },
        success: function (data, textStatus, XmlHttpRequest) {
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {

            if (XmlHttpRequest && XmlHttpRequest.responseText) {

                alert("Error while updating " + odataSetName + " ; Error – " + XmlHttpRequest.responseText);
            }
        }
    });
}
You can call this function like below;
     var pp = new Object();
     // Update fields
     pp.new_ApprovedOn = "2013/12/06";
     Update(accountId, pp, "accountSet");
MSDN Sample for JSON : http://msdn.microsoft.com/en-us/library/1bb82714-1bd6-4ea4-8faf-93bf29cabaad#BKMK_UsingJQuery

OData System Query Options Using the REST Endpoint : http://msdn.microsoft.com/en-us/library/gg309461.aspx

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...