OData Query to retrieve records based on record Guid

To retrieve the record based on Guid, below is the small code snippet to use.

function getRecordFromGuid() {
    var resultData = null;
    var uniqueId =RecordGuid;
    var oDataEndpointUrl = "http://yourservername/XRMServices/2011/OrganizationData.svc/";
    oDataEndpointUrl += "new_tempSet?&";

    oDataEndpointUrl += "$select=new_name&$filter=new_tempid eq guid'" + uniqueId + "'";
    $.ajax({
        type: "GET",
        url: oDataEndpointUrl,
        //data: jsonAccount,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function result(data) {
            resultData = data.d.results;

        },
        async: false,
        error: function (xhr, textStatus, errorThrown) {
            errorCallback(this._errorHandler(xhr));

        }
    });

    if (resultData != null)
        return resultData;
    else
        return null;
}





You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

OData Query to retrieve records based on picklist value

There may a scenario to retrieve records using a picklist value throug OData query. Below is the small piece of code to retrieve the same.

function GetRecordsBasedonPicklistValue() {
    var plateType = 427345000;//Picklist value
    var oDataEndpointUrl = "http://youservername/xrmservices/2011/OrganizationData.svc/";
    oDataEndpointUrl += "new_itemtypeSet?&";
    oDataEndpointUrl += "$select=new_name&$filter=new_picklistype/Value eq " + plateType;
    $.ajax({
        type: "GET",
        url: oDataEndpointUrl,
        //data: jsonAccount,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function result(data) {
            resultData = data.d.results;
        },
        async: false,
        error: function (xhr, textStatus, errorThrown) {
            errorCallback(this._errorHandler(xhr));
        }
    });
    if (resultData != null)
        return resultData;
    else
        return null;
}



You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

An Unexpected error occured while using RetrieveEntityRequest in MS CRM 2013

"An unexpected error occurred".

This error is really frustrating, this will not give any clue on why this error is occurring.

It took half day to resolve my issue. My project development server has MS CRM 2013 and SIT server has MS CRM 2013 with SP1.

On my development server, we have used RetrieveEntityRequest to read metadata of an entity and it is working fine. So we have moved the code to SIT and started throwing an error as "An unexpected error occurred".

This error is occuring because of Microsoft.Xrm.sdk.dll is older version when deployed the code on SIT server.

So to resolve the issue, we have to rebuild the code with the server version dlls and deploy it. In this case, I have taken Microsoft.Xrm.sdk.dll from SIT server, rebuild the code and deployed.

Now it is started working.

Even after you made the above changes, there are chances of your code may not work because of older version of dlls might be installed in GAC.

If this is the case, uninstall older version of dll and install newer version of dll in GAC.

Hopefully, this solution may save few people's half day time.

Happy coding.....


You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more approach we can improve the performance bit more.
In IIS setting of a website where MS CRM is hosted, there we can change the Output Cache property. By changing this property to true, initially any entity record load may take bit time; later on it will open the records in much lesser time. This is quite a good approach to improve the performance.
Below screenshot explains where to change the output Cache settings

Open IIS, click on Microsoft Dynamics CRM site-> On Right side Panel click on Feature View-> Configuration Editor









































(source of below description: MSDN)
What is omitVaryStart:
Gets or sets a value indicating whether the vary header is enabled.


true if the vary header is enabled; otherwise, false. The default is false.

The vary header indicates the request-header fields that the server uses to determine which of multiple cached responses are sent in response to a client request. The default for the OmitVaryStar property is false. By default, ASP.NET sends the vary header in all POST requests, as well as in all GET-request query strings. If the OmitVaryStar is true, ASP.NET omits the vary header when returning the response for cached pages, provided that the GET request to a response is cached with no VaryByCustom property and thePOST request to a response is cached with no VaryByParam property and no VaryByCustom property.




You may like below posts

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Performance Center in MS CRM 2013

To analyse the performance of a CRM form, SP1 of MS CRM 2013 introduced performance center. It will gives you the detailed information on how much time form is taking to load.

To open Performance Center on CRM, press  Ctrl+Shift+Q




Note: This tool only displays with CRM 2013 once you have Service Pack 1.


You may like below posts

Improving MS CRM Performance

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

Creating OrganizationService in MS CRM

Mostly creation of an organization service can be done in two ways.

1. Using user credentails
2. Using Network credentials.

1. Creating an organization service using credentials:

            OrganizationUri = new Uri(ConfigurationManager.AppSettings["OrgURL"].ToString());
            HomeRealmUri = null;
            Credentials = new ClientCredentials();
            Credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username","password","domain");
            DeviceCredentials = new ClientCredentials();
            _serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, DeviceCredentials);
            _service = (IOrganizationService)_serviceProxy;

2. Creating organization service with Network credentials.

            OrganizationUri = new Uri(ConfigurationManager.AppSettings["OrgURL"].ToString());
            HomeRealmUri = null;
            Credentials = new ClientCredentials();
            Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            DeviceCredentials = new ClientCredentials();
            _serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, DeviceCredentials);
            _service = (IOrganizationService)_serviceProxy;

Note: Generally if you are using Network credentials for creating organization service, you may not able to create the organization service because of web service or aspx pages on different servers or on different port with in the same server.

Network credentials will work only if you hosted your custom pages on same server and same port where CRM hosted.

Hosting custom pages on CRM port is unsupported in MS CRM 2013.

1. If you hosted custom pages on different port, so you have to use user credentials (1st approach) to create an organization service. If you use this approach, you may face an issue on security roles. Because you are creating an organization service using particular credentials(Service Credentials, System Administrator or any one's) security roles will work according to the credentials we have used.
2. If you hosted the custom pages on same port where MS CRM 2013 hosted, according to MS CRM 2013 it is unsupported.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Calculated Field in Dynamics CRM 2015

So far in Dynamic CRM 2013, If we want to calculate data in different fields we have to write down our own JavaScript method to calculate it. But CRM 2015 has introduces new concept called Calculate fields.

I would like to walk you through step by step with an example on this concept.

Ex: Here I would like to calculate an employee salary with few salary components like basic, variable, deductions.

I have created Basic, Variable and Deduction fields as Decimal number like any other fields.

Here Total field should be created with bit different. CRM 2015 has Field Type along with Data Type as shown in below screen



While creating you have to set the Field Type as "Calculated" and click on Edit button, on edit button click itself it will create the field first and navigate you to Calculate field screen. This field will be looks like below.



And write down you logic there on the screen.



Here, whenever you set field type as Calculated field then it will be read only and value will be reflected on save of the form.



















Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...