Sunday, 24 August 2014

CRM 2013 Using addCustomFilter() to get Filtered Lookup Field based on Linked Entity

We all have known that in CRM 2013 we can filter the lookup field using easier method compared to CRM 2011, that is using addCustomFilter() combined with addPreSearch() function.
This is one of the example how to use it, to filter contact based on email that contains
function onLoad()

function addEventHandler() {
    // add the event handler for PreSearch Event

function addFilter() {
   //find contact contains this
   var email = "";

    //create a filter xml
   var filter = "<filter type='and'>" +
                "<condition attribute='emailaddress1' operator='like' value='" + email + "'/>" +

    //add filter

Call the onLoad function during form onLoad event.

That code is looks good and it will work, yes, it will.

And if you notice, this is a very simple way, compared to the old code, using addCustomView(), which you need to build your own custom view and don’t forget to build layoutXML as well.

This is the addCustomView().
Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)

However, there is a limitation, not only that is because those functions can only work for lookup field in the Refreshed UI Entity Form (it means cannot work for Price List Item, Quote Product, etc.), but this filter, if you notice, it can only work to filter using the attribute that is a part of that entity. So, it cannot be used to filter an entity based on the field from another entity.

The above example is to filter contact by email address (email address is one of the contact attribute), what if we are going to filter an entity record based on another related entity, for example in the Lead form, it has Existing Contact lookup field, then the users want to filter to show only Contact based on the Account Number or based on the Website/Email Address of Account or based on the Account Name that compared to the obtained Company Name in Lead form .

If you notice, the filter that is supported is currently just using the node that is started from <filter>..

//create a filter xml
    var filter = "<filter type='and'>" +
                 "<condition attribute='emailaddress1' operator='like' value='" + email + "'/>" +

However, from that XML we get (see the example below), if we are using another related entity as the filter, it is using <linked-entity>, which is not allowed in the addCustomFilter() method.

This is the example of the generated XML with criteria based on the another related entity’s field:

*The XML to get Contact based on Account’s email address.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
 <entity name="contact">
   <attribute name="fullname" />
   <attribute name="parentcustomerid" />
   <attribute name="telephone1" />
   <attribute name="emailaddress1" />
   <attribute name="contactid" />
   <order attribute="telephone1" descending="false" />
   <link-entity name="account" from="primarycontactid" to="contactid" alias="ab">
     <filter type="and">
       <condition attribute="emailaddress1" operator="like" value="%example%" />


We cannot use these lines as variable filter.
<link-entity name="account" from="primarycontactid" to="contactid" alias="ab">
     <filter type="and">
       <condition attribute="emailaddress1" operator="like" value="%example%" />

As we know that the only way is still using the old-fashioned CRM 2011 Code, that is using addCustomView() with many parameters that you might not want to build anymore.

Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)

So, we should build our own fetchXML + layoutXML as well, in fact you have built your own view and you just need to filter it.

Then, as the alternative, you can use another code to find that related entity id, see this example:

var filter = "<filter type='and'>" +
             "<condition attribute='parentcustomerid' operator='eq' uiname='Fourth Coffee (sample)' uitype='account' value='{DBBB8E56-B9D9-E311-9410-001CC4EECDD6}' />" +

    //add filter

You can use OData Query to find the Account Id.

The best part that you should do is by getting the AccountId and I believe the OData Query is will be your best friend.
To get used using odata, you can refer to my another blog post:

Another limitation in addCustomFilter() is it only supports 'And'
(based on this link:

If you need more than one Account Id, then you might need to add Operator IN, see this example:
<filter type="and">
        <condition attribute="accountid" operator="in">
          <value uiname="Fourth Coffee (sample)" uitype="account">{DBBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>
          <value uiname="Litware, Inc. (sample)" uitype="account">{DDBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>
          <value uiname="Adventure Works (sample)" uitype="account">{DFBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>

You might choose whether you want to use addCustomView() with those many required parameters or addCustomFilter() with that limitation and have to find the ID, but with no need to pass many parameters as the addCustomView() required.


1. To use addCustomFilter() to filter based on the same entity field:
function addFilter() {
   //find contact contains this
   var email = "";

    //create a filter xml
    var filter = "<filter type='and'>" +
                 "<condition attribute='emailaddress1' operator='like' value='" + email + "'/>" +

    //add filter

2. To filter based on the related entity (one record only):

 //create a filter xml
 var filter = 
"<filter type='and'>" +
     "<condition attribute='parentcustomerid' operator='eq' uiname='Fourth Coffee” (sample)' uitype='account' value='{DBBB8E56-B9D9-E311-9410-001CC4EECDD6}' />" +

3. To filter based on the related entity (multiple records)

//create a filter xml 
var filter =
"<filter type='and'>" +
        "<condition attribute='accountid' operator='in'>" +
          "<value uiname='Fourth Coffee (sample)' uitype='account'>{DBBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
          "<value uiname='Litware, Inc. (sample)' uitype='account'>{DDBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
          "<value uiname='Adventure Works (sample)' uitype='account'>{DFBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
        "</condition>" +
//or you can just use this (uiname and uitype are not mandatory)

//create a filter xml
 var filter =
"<filter type='and'>" +
        "<condition attribute='accountid' operator='in'>" +
          "<value>{DBBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
          "<value>{DDBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
          "<value>{DFBB8E56-B9D9-E311-9410-001CC4EECDD6}</value>" +
        "</condition>" +

Result for Number 2 (Single Record):

customfilter single value

Result for Number 3 (Multiple Records):

customfilter multiple value

*Using the addCustomFilter() has advantage it will not break the column order and position you defined in the Customization, because you are just changing the criteria to filter, not creating a new custom view, so that you will not find any issue like I found and posted here.

Hope this helps!


Display the Missing Associated View in CRM 2013

Sometimes, you need to show the Associated View from the Relationship in CRM 2013, you know that adding new subgrid might be making your Form UI looks cluttered, then you should go to the Form Editor and add the Navigation.

But, some relationship are hidden and cannot be shown in CRM 2013.

So, how do we handle this?

For example, we cannot show the Associated View of related Lead from Account/Contact and we cannot show the related Lead owned by User in User form.

So, to handle this case, you should create a custom Navigation link + the custom Web Resource, you should refer first to this link, Thanks to Amreek Singh for the nice post:

But, in CRM 2013, since the User Interface was changed and the parameters required were revamped as well, so the constructed URL will give error if you apply to CRM 2013.

So, still using the methods mentioned in that great post, in CRM 2013 you should add another parameter.
In the building URL, you should use this:

 //building a url 
var sUrl = "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&pagemode=iframe&security=852023&tabSet=" + relName&rof=false&inlineEdit=1; 

Add the &inlineEdit=1 to show the CRM 2013 Command Bar (not Nav Bar)

So, the complete Web Resource code:
<html xmlns="" >
    <title>Untitled Page</title>
    <style type="text/css">html,body{font-family: Segoe UI, Tahoma, Arial;background-color: #d6e8ff;border: 0px; margin: 0px; padding: 0px;}</style>
    <script type="text/javascript" language="javascript">


            //get the context
            var Xrm = window.parent.Xrm;

            //get the current object id
            var oId =;

            //get the object type
            var oType = Xrm.Page.context.getQueryStringParameters().etc;

            //set Relationship Name
            var relName = "lead_owning_user";

            //building a url var sUrl = "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&pagemode=iframe&security=852023&tabSet=" + relName&rof=false&inlineEdit=1;
            //get relative path with orgname as required
            var relativeUrl = Xrm.Page.context.prependOrgName(sUrl);
            window.location = relativeUrl;

And this is the appearance of that ‘custom Associated View’



and with InlineEdit = 1


*Remember, the behavior will be shown as expected if you show the web resource in the Navigation link in the parent Entity Form.

To make your job easier, you might try to test the URL first, copy it into the browser and execute it, before you put into the code.

The URL will be having this format:

http://servername:port/organizationname/userdefined/areas.aspx?oId=DB4A2D57-FBBA-E311-9403-  001CC4EECDD6&oType=1&pagemode=iframe&security=852023&tabSet=lead_customer_accounts&rof=false

Hope this helps!


Show Field as Group By or Axis X (Horizontal/ Category Axis) from Another Related Entity in CRM 2011/2013 Charts

A brief post, I don’t know whether you have known about this trick, but I just realized that this is possible.
Well, at one occasion, I had a demo to prospect and they want to see the Chart Capabilities in CRM 2013, especially to show Cases based on the Customer Location (can be City, State, or Country).

The problem is, currently, the charts (out of the box charts) are only supporting to display chart with Axis X or Group By from the same entity fields.


For example,
  • Case by Case Origin
  • Case by Create On
  • Case by Owner
  • Case by Priority
  • Case by Case Stage
  • Case by Case Type
  • Case by Contract
  • Case by Created By, and
  • Case by Customer, and so on
The maximum level that can be possible is Case by Customer.

How about if I want to show Case by Customer Location (by City, by State, or by Country) or to show Case by Contract Expired Date.

I though it is impossible without modifying the XML and I don’t want to show that because the audiences are definitely from Business Users and non-developers.

Then, I was thinking that I have to create 3 custom fields in Case entity, which I will auto-populate using Workflow every time create Cases from Customer.

But, what if the Address from Customer is changed, then I have to create another custom business process to Update those 3 fields in the related case record.

Finally, I found a solution which I didn’t expect before and it is so easy.

So, first of all, you need to create a new view or modify the existing view.
And.. Then, add the Column from the related Entity, in this case I want to show Case by Customer Location, then I add columns from Account:
  1. City
  2. State
  3. Country


Then, I save this view.

Without publishing, you can can go back to the Case Charts.

Once you go back to the Case Charts then create a new Chart, you can see those 3 new fields (from Account – a related entity) were added and were available to be selected as the Horizontal Axis (Axis-X)

Yess..Bump..Now you can see...
Those fields are available as Category Axis that you can use..


Then, I am be able to show Chart, Case by Customer City, State, or Country.




I don’t know now whether you have known about this trick, but I just found it without any expectation before. Smile
*No coding, no XML modification :)

Hope this helps!

Thank you.

Sunday, 17 August 2014

Uninstall Microsoft Dynamics CRM Rollup

Many people and my ex colleagues were asking me how to uninstall CRM Rollup, so in this post I give the steps how to uninstall the CRM Rollup.

1. Go to Control Panel

2. Go to Program and Features

3. Click the View Installed Updates

uninstall rollup

4. Find the Microsoft Dynamics CRM Server 2011 or 2013

5. You can see the installed Rollup that you can Uninstall.

*But, please be aware that not all of the rollup or service pack can be uninstalled, you should be aware by seeing the detail information provided by Microsoft in the MSDN articles before installing the rollup to avoid the risks before it becomes a disastrous plan.

Please watch out the Removal Procedure

For example:

It is possible to uninstall the Rollup 12

But, not for Rollup 5.


You also can search to another expert blog to find out whether CRM Rollup is possible to be uninstalled or not, for example this blog from Ben Hosk:

So, please, everyone, be careful before you do the rollup installation or turn off your automatic updates download if you think that your company or server environment is not ready to install the new rollup because it will result to fundamental changes that might not be able to be rolled back.

Especially, for those who have reports or apps or integration points accessing direct database or unsupported customization in CRM, this thing should be an important info for you.

Hope this helps!

Converting WhatsApp Message to Case in CRM 2013

First of all by writing this post, I also want to celebrate the Independence Day of my Country. I would like to say Happy 69th Birthday to my Nation, Indonesia, even though, now I and you are in long-distance relationship Smile, but my heart is always for you!

Okay, let’s continue to my post…

I was preparing the demo for my pre-sales activity and I was thinking how to ‘integrate’ a famous messenger application to CRM. As we know that WhatsApp is one of the most reliable communication application to connect everyone by using their smartphones and only using internet or data plan.

Many Salesperson or Insurance Agent are using smartphone everyone and they might communicate with their customers anytime and anywhere, so they will use WhatsApp for a better and an easier way since WhatsApp supports image transfer as well. Customers can send their information, such as location with the image as well, for example they need a towing service when they were stuck at the road or they want to submit a claim, then they will send the image of the policy and the car appearance, including the newest condition of the broken car as well. They usually often contact the Agent, not directly call the Customer Service. Then the insurance agent can easily collect the required information that might be needed by the related department. It is so easy for them.

So, it made me to keep thinking how to convert the WhatsApp Message between Customer and the Salesperson or Agent to CRM Case.

Luckily, Microsoft Dynamics CRM 2013 SP1 and Microsoft Dynamics CRM 2013 Online with Springwave Update have the capability to Convert Email to Case. So, I have an idea to utility that feature.

And yes, I check the WhatsApp feature, and it can send the Conversation as email, so I think my idea and my research here will work, just need to finish a fine tuning.

So, first of all, I will complete the setup of an Incoming Email, I am using Email Router and I create a Queue with that email. Make sure it works first.


Then, I will create an Email to Case Creation Rule with the help of that newly created Queue.


Well, now I want to have a new Origin of Case, I add new Type: from WhatsApp

And thanks for my friend, @RajYRaman, because I have an idea that it is possible to add New Case Origin with the beautiful logo as the icon after I read his tweet :).

Please refer to this post:

to get detail how to add new Case Origin and Add the icon as well.
So..Now what….I don’t have time to create new Apps in Android nor integration tool or Web Service to connect them…

Okay, actually, they’ve already had their methods of friendship, yes, this is Email…

Then, I learned how the ‘Email Conversation’ feature in WhatsApp works and with what kind of format. And it is actually has structured format for Subject and Body and also the Attachment.

After that, I create a workflow to update the origin to WhatsApp with certain rules:


and Update the Origin to WhatsApp


*I just use the default format of WhatsApp email and simple rules for my demo, if your client has complicated SOP, then you should write your own plugin to convert to what they expected.

*You also can have dedicated queue for WhatsApp to create a separated email, for example:

Then…it is the time to check out and test the result.

I am playing role as Customer, I send message through WhatsApp to my Agent.
And now…

I am the Agent, I can send the Conversation through email.


I also can send the Picture as well.


I send the email with default format and nothing to change.


And Send it…..

And I log in to CRM..And I get the Case:


Then, you can the Email and Attachment of this case as well:


The conversation is stored in the .txt file


And of course, you can get the image as well, it can be broken car or new car for new application.


And the Voice Recording File as well.


SO…the User can hear the message and do the next action or escalation.

Yes, the customer can send the images of their broken car or new car for new insurance application and say message to the agent as well.

*If you need more complicated scenario, you might need a plugin to convert your own rules to the case.

For example, this case need to tie to the correct customer, then you can use the title:
WhatsApp Chat with +6012…

You can use the number to indicate the customer number and get the Customer Id using custom Plugin

And if you want to convert the .txt to another format, you also need a plugin to do it, this is the prototype to convert WhatsApp Message to a New Case in CRM 2011 by utilizing WhatsApp and CRM 2013.

Hope this helps!

Add WhatsApp and Other Source as New ‘Case Origin’ with Custom Icon in CRM 2013

In my post, I was adding WhatsApp message as the new Case Source, so in this post, for those who still need further explanation how to add WhatsApp as new Case Origin, I will explain how to add WhatsApp as new Case Origin.

*FYI, this is not only to add the WhatsApp, it also can add other case origin as many as your company needs it.

First of all, please read this excellent blog:

and this link also for Spanish version:

Okay, now here we go.

1. Open the Customization

2. Go to Case entity

3. Go to ‘Case Origin’ field

4. Edit the field:


5. Add new Item, add the Label and Value


*Please remember your given value for this new Case Origin.

6. Save and Close and Publish it.

7. Go to Web Resources section.

8. Create a new Web Resource with type = .PNG

You can download the WhatsApp image 16x16 from here (you can choose):


*16x16 Only :)

9. Give the name with format: Incident_origincode_iconxxxxxxxxx.png

with the xxxxxxxxx is the given value for the new origin code.

For example:

or Incident_origincode_icon100000002.png

*Please be aware that on the website there is a typo,
it was typed:‘Incident_orgincode_icon#.png’
The correct one: ‘Incident_origincode_icon#.png’

*This is so important, otherwise, you will not get what you expected..


If you don't change it, it will not work.


*Remember you give the value at the step #5, but without comma.

*And so far I tried using different prefix other than new_ and it did not work, so I recommend you to use prefix new_

Don't use another prefix.

Save and Publish It.

10. Create a new Case with Origin = ‘WhatsApp’ and see the result in the Case View.


*If you choose the Green Color as your icon


*Another green icon.


If you don't create new custom icon, then it will give Yammer Iconfor the new Custom Case Origin.

Please refer to my other post to convert WhatsApp message to a Case in CRM 2013.
Check my Post!

Since it is also applicable for another case origin, so you can use the same method to add other case origin, such as Skype, YM, etc, just see this colorful icon.

Or you just want to have a gray, black, and white color, it is up to you :)

*Just down use another icon size, it is very recommended to have 16x16, if you still use another size, then it will give you a very unstructured view.

Hope this helps!