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

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...