Posts Tagged ‘CRM 2011’

Merging solutions in CRM 2011

July 17, 2013 2 comments

Imagine you have 2 developers (Dev 1 & Dev 2) in your team working on 2 different organizations and 2 solutions, at the time of every release, you need to merge the components of both developers in to 1 solution.

One way is

  • Import Dev 1 & Dev 2 solutions in to another new organization.
  • Create a new solution and add the components of both solutions manually
  • This is easy if Dev 1 & Dev 2 solutions has less components.

What if the components are huge? you need to manually pick and add components both solutions in to a single solution or

Another way of merging solutions

  • Export & Save the both Dev 1 & Dev 2 solutions
  • Extract the saved solution .zip folders
  • Open “Solution.xml” files in both solutions in a notepad
Solution components

Solution components

  • In the <UniqueName> node, provide same unique name in both “Solution.xml” files
SolutionXml file

SolutionXml file

  • Import them back to new a organization
  • After the import, we get a new merged solution.
  • This is easier way of merging if the solutions has lot of components

Refer below MSDN video for more details


Categories: CRM 2011 Tags: , ,

event.returnValue is not working after UR 12 – Fix

July 15, 2013 2 comments

We use event.returnValue=false statement, to stop the event execution. (i.e., I can stop my crm form’s save action, if I write event.returnValue=false statement on my onsave() event).

After I upgraded to UR12, I was getting script error, if I use the event.returnValue statement.


  • Update Rollup 12 and December 2012 Service Update support additional browsers by generating HTML that supports W3C standards.
  • This requires removing dependencies on HTML components (HTC) that are specific to Internet Explorer.
  • Hence event.returnValue statement has been deprecated


  • Use context.getEventArgs().preventDefault() function to cancel the event execution

How do I use this

  • First to get “context”, enable the OnSave event handler to pass the execution context as the first parameter to the OnSave event handler.
  • Open customization form -> Form Properties and in “Handler Properties” window, select the “Pass execution ….” checkbox
  • Pass execution context

    Pass execution context

  • Next in your Jscript , read the context as first parameter

function onsave(context) {

// Prevent the event execution



Get more details on latest CRM JScript changes from this link


CRM online instance opening only in Mobile version – Fix

July 10, 2013 2 comments

The other day, when I upgraded to IE 11 browser and when I browse my CRM online URL, I was getting only mobile version (i.e., http://

CRM Mobile Version

CRM Mobile Version

Even if i explicitly provide the URL http://, it was redirecting to Mobile version Reason

  • CRM online is not compatible with IE 11


  • Add CRM online site to IE 11 compatibility list
  • Go to Tools -> Compatibility View Settings
  • Add the “” website to compatibility view settings by click on “Add”
Comaptibility Settings

Compatibility Settings

  • If its “OnPremise” add CRM server name to compatibility view settings.
  • Refresh the browser


Retrieve records with Fetchxml using Jscript – CRM 2011

June 20, 2013 1 comment

Retrieve the records using FetchXML is a convenient way as we can form the FetchXML easily using the ‘Advanced Find’ .

Download Fetch XML

Download Fetch XML

Once you have the FetchXML ready, below is the JScript to execute and read the result set.

  • In this sample, I am fetching records from custom entity “Bikes” which has relationship with ‘Contact’ entity. (i.e., Fetch all the bikes of a Contact whose full name contains ‘Raj’)
  • Note – I am using “xrmservicetoolkit” helper Jscript which is available in CodePlex. You just need to download the Jscript and refer to your CRM form.

function getBikesByContactName() {

var fetchXml =

“<fetch mapping=’logical’>” +

“<entity name=’raj_bike’>” +

“<attribute name=’raj_name’ />” +

“<attribute name=’createdon’ />” +

“<link-entity name=’contact’ from=’contactid’ to=’raj_customerid’ alias=’ad‘>” +

“<attribute name=’fullname’ />” +

“<filter type=’and’>” +

“<condition attribute=’fullname’ operator=’like’ value=’%raj%’ />” +

“</filter>” +

“</link-entity>” +

“</entity>” +


// Execute the fetch

var bikes = XrmServiceToolkit.Soap.Fetch(fetchXml);

// Get the results by loop through ‘bikes’

for (var indxBikes = 0; indxBikes < bikes.length; indxBikes++) {

alert(“Bike Name – “+bikes[indxBikes].attributes.raj_name.value);

alert(“Created On – “+bikes[indxBikes].attributes.createdon.value);

// Get the related entity (i.e., Contact) attributes using LinkEntity alias)

alert(“Related entity attribute (Contact Name) – ” + bikes[indxBikes];




Filtering Lookup view based on custom logic CRM 2011

June 17, 2013 1 comment

In one of my requirement, I have to filter my lookup view results based on another lookup field value.

I have 2 Lookup fields on my form

  • Product
  • Product Category

When I click on “Product” lookup, I have to show only Products with category as “Product Category” field value.

Filter Lookup View

Filter Lookup View

We can achieve this requirement using Jscript by following below steps

  • Create a new view with our filter
  • Use the SDK method addCustomView, to add newly created view for the lookup dialog box
  • Set this view as default view
  • Disable the view selector to avoid user to select other views from Lookup dialog
  • Put above logic in a function register it on “onchange” event of “Product Category” field

Below is the Jscript function

function createAndSetLookupView() {

// Some GUID but only needs to be unique among the other available views for the lookup

var viewId = “{CB6F8184-D7C2-4664-9FAB-18FD9DCDB22A}”;

// Name of the view

var viewDisplayName = “My filtered view”;

// Prepare the xml with columns to display and filter

// Tip : Use Advanced Find to prepare th FetchXML

var fetchXml = “<fetch version=’1.0′ ” +

“output-format=’xml-platform’ ” +

“mapping=’logical’>” +

“<entity name=’new_product’>” +

“<attribute name=’new_productid’ />” +

“<attribute name=’new_name’ />” +

“<attribute name=’new_categoryid’ />” +

“<attribute name=’createdon’ />” +

“<order attribute=’new_name’ ” +

“descending=’false’ />” +

“<filter type=’and’>” +

“<condition attribute=’new_categoryid’ ” +

“operator=’eq’ ” +

“uiname='” + {categoryName} + “‘ ” +

“uitype=’new_category’ ” +

“value='” + {categoryGUID} + “‘ />” +

“</filter>” +

“</entity>” +


var layoutXml = “<grid name=’resultset’ ” +

“object=’1′ ” +

“jump=’new_name’ ” +

“select=’1′ ” +

“icon=’1′ ” +

“preview=’2′>” +

“<row name=’result’ ” +

“id=’new_productid’>” +

“<cell name=’new_name’ ” +

“width=’150′ />” +

“<cell name=’new_categoryid’ ” +

“width=’150′ />” +

“<cell name=’createdon’ ” +

“width=’100′ />” +

“</row>” +


try {

// Lookup field which you want to add new view

var lookupControl = Xrm.Page.ui.controls.get(“new_productid”);

// Add the created view to Product lookup and set this view as default

lookupControl.addCustomView(viewId, “new_product”, viewDisplayName, fetchXml, layoutXml, true);

//Disable “View Selection” dropdown of “Product” lookup dialog

document.getElementById(“new_productid”).setAttribute(“disableViewPicker”, “1”);


catch (e) {

alert(“Error in createAndSetLookupView() – ” + e.description);




Retrieve associated records (N:N related)

In CRM, If you create N:N relationship between 2 entities, it creates an intermediate entity (i.e., Relationship Entity) with 3 fields

  • Primary key field of “Relationship Entity”
  • Entity 1 Primary Key field
  • Entity 2 Primary Key field
N toN Relationship

N to N Relationship

In this sample, I have 2 custom entities “Bike” and “Bond” with N:N association. (i.e., A ‘Bike’ can have N no of ‘Bonds’ and a ‘Bond’ can be associate with N ‘Bikes’)

To get all the ‘Bonds’ of ‘Bike’ with name “Honda”, below is the query expression.

string entity1 = “raj_bike”;

string entity2 = “raj_bond”;

string relationshipEntityName = “raj_bike_bond”;

QueryExpression query = new QueryExpression(entity1);

query.ColumnSet = new ColumnSet(true);

LinkEntity linkEntity1 = new LinkEntity(entity1, relationshipEntityName, “raj_bikeid”, “{Entity 1 Primary key field (i.e.,raj_bikeid)}“, JoinOperator.Inner);

LinkEntity linkEntity2 = new LinkEntity(relationshipEntityName, entity2, “raj_bondid”, “{Entity 2 Primary key field (i.e.,raj_bondid)}“, JoinOperator.Inner);



// Add condition to match the Bike name with “Honda”

linkEntity2.LinkCriteria = new FilterExpression();

linkEntity2.LinkCriteria.AddCondition(new ConditionExpression(“raj_bikename”, ConditionOperator.Equal, “Honda”));

EntityCollection collRecords = service.RetrieveMultiple(query);

Note : To retrieve columns from Entity 2, set ‘Alias’ to ‘LinkEntity2’.


Copy a security role programmatically – CRM 2011

In one of the requirement, we have to create a new security role by copying an existing role in a Plug-in.

The whole requirement break down to 3 steps

  1. Create a new security role
  2. Get all the existing role privileges by using “RetrieveRolePrivilegesRoleRequest
    1. RetrieveRolePrivilegesRoleResponse” contain, “RolePrivileges” property, with collection of privileges & access level
    2. Role Privilages

      Role Privileges

  3. Add the retrieved role privileges to the newly created role by using “AddPrivilegesRoleRequest

Below is the code for step 2 & 3

Guid existingRoleId = new Guid(“C85F0FFF-4C80-E211-A877-1CC1DE79B4CA”);

Guid newRoleId = new Guid(“B6690FFF-4C80-E211-A877-1CC1DE79B4CA”);

// Step 2

RetrieveRolePrivilegesRoleRequest getPrivilagesRequest = new RetrieveRolePrivilegesRoleRequest();

getPrivilagesRequest.RoleId = existingRoleId;

RetrieveRolePrivilegesRoleResponse privilagesResponse = (RetrieveRolePrivilegesRoleResponse)service.Execute(getPrivilagesRequest);

if (privilagesResponse != null && privilagesResponse.RolePrivileges != null){

// Step 3

AddPrivilegesRoleRequest addPrivilagesRequest = new AddPrivilegesRoleRequest();

addPrivilagesRequest.Privileges = privilagesResponse.RolePrivileges;

addPrivilagesRequest.RoleId = newRoleId;

AddPrivilegesRoleResponse addPrivilagesResponse = (AddPrivilegesRoleResponse)service.Execute(addPrivilagesRequest);