Search This Blog

Wednesday, December 24, 2014

Enable Hidden Button in CRM 2013 Using Ribbon WorkBench

Open Ribbon editor and select entity on which you want to enable button. In this example i enable Export to Excel Button on form.

Click on Command Bar and select button then expand command. Now right click and select Edit Display Rule




Now <Remove "Mscrm.HideonCommandBar" Rule. and other rule IsCore to "True"

This will Display "Export to Excel" Button on Competitor form.

Saturday, October 25, 2014

Filter Lookup values in CRM 2011 and CRM 2013 without Javascript

In this Example I filter cities of a country. Follow following steps:

  •  Every country have many cities, so i create a 1:N relationship of cities with country entity i.e. in city entity i have lookup of country entity. 
  • Now in Account entity i create two lookups one of Country entity and second city entity.

  • In city entity I added some sample records of cities and also select their country so that city will be filtered related to that country.                                                                                     



  • Now open lookup of city and edit filter record settings as shown in below image. 





  • Filtered records are shown below that When I select country Pakistan only cities related to Pakistan are shown and when I select country Afghanistan only cities related to Afghanistan are shown.                                                                                                                                  















Thursday, October 23, 2014

Change Optionset Values on change of other optionset values using JavaScript in Microsoft Dynamics CRM 2011 and 2013

function optionSetChanged() // apply this function of change of country field
{

    // on the base of country change cities

    var _collection = getCollection();
    var _selectedCity = null;
    var _cityOptionset = Xrm.Page.ui.controls.get("city");  
if (_cityOptionset != null)
    _selectedCity = _cityOptionset.getAttribute().getValue();
var _cityOptions = _cityOptionset.getAttribute().getOptions();
    var _selectedCountry = Xrm.Page.getAttribute("Country").getText();    
    // If Country is empty, then clear the City field.
    if (_selectedCountry == "")
{
        _cityOptionset.clearOptions();
    }
    else
{
        for (var i = 0; i < _collection.length; i++)
{          
if (_selectedCountry.toLowerCase() == _collection[i].Country.toLowerCase())
{                _
cityOptionset.clearOptions();
            for (var j = 0; j < _collection[i].Cities.length; j++)
{                  
for (var k = 0; k < _cityOptions.length; k++)
{                      
if (_collection[i].Cities[j].toLowerCase() == _cityOptions[k].text.toLowerCase())
{                          
_cityOptionset.addOption(_cityOptions[k]);
                        break;
                        }
                    }
                }
                break;
            }
        }    
if (_cityOptionset != null && _selectedCity != null)
            _cityOptionset.getAttribute().setValue(_selectedCity);
    }
}


function getCollection() {

    var _collection = new Array();  
var India_Cities = new Array("NewYork");
    var India_obj = { Country: "USA", Cities: India_Cities };
    _collection.push(India_obj);

    var Srilanka_Cities = new Array("Lahore");
    var SriLanka_obj = { Country: "pakistan", Cities: Srilanka_Cities };
    _collection.push(SriLanka_obj);

    var USA_Cities = new Array("Mumbai");
    var USA_obj = { Country: "India", Cities: USA_Cities };
    _collection.push(USA_obj);

    return _collection;
}

Thursday, September 25, 2014

Run Workflow using javascript CRM 2013

only change GUID of your workflow
function RunWorkflow() {
     var _return = window.confirm('Are you want to execute workflow.');
     if (_return) {
         var url = Xrm.Page.context.getServerUrl();
         var entityId = Xrm.Page.data.entity.getId();
         var workflowId = '87038619-3DA9-47A9-92A8-263E5C0533B4';
         var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
         url = url + OrgServicePath;
         var request;
         request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                       "<s:Body>" +
                         "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
                           "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
                             "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
                               "<a:KeyValuePairOfstringanyType>" +
                                 "<c:key>EntityId</c:key>" +
                                 "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
                               "</a:KeyValuePairOfstringanyType>" +
                               "<a:KeyValuePairOfstringanyType>" +
                                 "<c:key>WorkflowId</c:key>" +
                                 "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" +
                               "</a:KeyValuePairOfstringanyType>" +
                             "</a:Parameters>" +
                             "<a:RequestId i:nil=\"true\" />" +
                             "<a:RequestName>ExecuteWorkflow</a:RequestName>" +
                           "</request>" +
                         "</Execute>" +
                       "</s:Body>" +
                     "</s:Envelope>";
         var req = new XMLHttpRequest();
         req.open("POST", url, true)
         // Responses will return XML. It isn't possible to return JSON.
         req.setRequestHeader("Accept", "application/xml, text/xml, */*");
         req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
         req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
         req.onreadystatechange = function () { assignResponse(req); };
         req.send(request);
     }
 }
 function assignResponse(req) {
     if (req.readyState == 4) {
         if (req.status == 200) {
             alert('successfully executed the workflow');
         }
     }
 }

Friday, July 11, 2014

Make field mode always same

So if you want to save a read only field you need to set the SubmitMode to be always, which ensures the value is sent to the database.



Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

Wednesday, June 18, 2014

Add New Module in CRM 2013 using Sitemap


  • First create new solution and only add sitemap in it.

  •   Export that solution.

  • Extract the solution and then open customization file in any editor. 
  • There is area tag which we call module in CRM like. Sale, service and marketing etc.
  • copy paste full area tag to create new module in CRM. 
  • In this example I add goal,tool,extensions group in new are and name it ProcessArea and instead of Resource Id I add Title: Process Area.


  • Save it and add these three files to zip.

  • Then import solution in CRM and refresh.