Sunday, 22 December 2013

Add a button on CRM 2013 form

How to add a button in CRM 2013 form ?

Hello CRM Developers,
          This is my new post to add a new button in CRM 2013.

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 yours to add a custom button in CRM 2013. So here is the simple java script code for CRM 2013 and it will work in CRM 2011(rollup 12) as well as in CRM 2013.

Step 1:- Add a attribute of type single line text on crm 2013 form. Or you may use existing one.

Step 2:- Add the fallowing code to your crm java script web resource. And call this function on page load.
function createButton() {
        var atrname = "YOUR ATTRIBUTE SCHEMA NAME";
        if (document.getElementById(atrname ) != null) {
        var fieldId = "field" + atrname ;
        if (document.getElementById(fieldId ) == null) {
            var elementId = document.getElementById(atrname + "_d");
            var div = document.createElement("div");
   = "100px";
   = "right";
   = "inline";

            childDiv = elementId.getElementsByTagName('div')[0]
   = "none";

            elementId .appendChild(div, elementId );
            div.innerHTML = '<button id="' + fieldId + '"  type="button" style="margin-left: 3px; width: 100%;" >CRM Form Button</button>';
            document.getElementById(atrname).style.width = "0%";
            document.getElementById(fieldId ).onclick = function () { YourOnClickFunction(); };


Sunday, 1 December 2013

retrieve with java script in crm 2013

Replacement of SOAP in CRM for single record retrieve in 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 single record 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.

  Retrieve Single Record with Java Script in CRM 2013

  Retrieve Multiple Records with Java Script in CRM 2013

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

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

function retrieveRecord(id, odataSetName, successCallback, errorCallback, _excontext) {
    var context = Xrm.Page.context;
    _executionObj = _excontext;
    var serverUrl = context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    //id is required 
    if (!id) {
        alert("record id is required.");
    }     //odataSetName is required, i.e. "AccountSet"
    if (!odataSetName) {
        alert("odataSetName is required.");
    //Asynchronous AJAX function to Retrieve a CRM record using OData
        type: "GET",
        async: false,
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
        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) {
                successCallback(data.d, 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 a record of a entity then write your function in this format.

//**********************************************************************************//*****************Your custom function for retrieving data********************
    function FunctionName() {
        var recordId= "guid of the record";
       if (_condition!= null) {
             retrieveRecord(recordId, "EntitySet", getRecord, null, null);


    function getRecord(data, textStatus, XmlHttpRequest) {
      if (data != null) {
                var attribute1 = data.attribute1 schema name;
                var attribute2 = data.attribute2 schema name;

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

For more info you can visit.

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