About Rawish Kumar Prajapati

Microsoft Dynamics CRM Consultant MCSE : Microsoft Business Application

Enable Custom Entities For Marketing Segment Dynamic Query

A segment in 365 for marketing app is an essential feature which lets you create a list of related contacts based on some criteria( similar to advanced find). Later it is used to target customers in a customer journey.

So when you create a new segment you have an option to create it as static or dynamic. A dynamics segment is what lets you add a query to filter contacts.

picture depicts a dynamic segment query designer

However, there is one thing that will bother you which is, it will not let you add a related custom entity to form a query ( click on add group and select union as relationship)


There is a settings available in Marketing app which will let you enable this feature for any entity in your system. To check this, go to Marketing App — > Settings Section:

Under Marketing Settings, click on advanced settings.
Now click on Customer Insights Sync under marketing setting section which will give you the list of entities on the right side with check boxes.

Enable for the entities which you need and click on publish from the header.

You might see the box is grayed out and you will not have option to enable. To enable the box you need to enable the change tracking on that entity. to do that you have to go to that entity definition and enable change tracking check box. https://docs.microsoft.com/en-us/power-platform/admin/enable-change-tracking-control-data-synchronization

Once published give it some half an hour.

Navigate to your query now and you will be able to add related entities to your query just like advanced find.

I hope this helps!


Dynamics 365 Latest API Limits

Have a look and plan things accordingly.

below link has full information : https://docs.microsoft.com/en-ca/power-platform/admin/api-request-limits-allocations

Dynamics 365 For Marketing – Retrieve Contacts From A Segment

I had a hard time trying to figure out a way to retrieve members from a marketing segment in my code.

The link-entity between contact and msdyncrm_segment isn’t materialized in CRM. I even raised it here :Basic operations on segments using the Segmentation API


Finally fetch xml came to rescue. You can use below xml which can be executed by WebAPI or Organization service and it works on both static and dynamics segments.

<fetch version="1.0" output-format="xml-platform" mapping="logical" returntotalrecordcount="true" page="1" count="5000" no-lock="false">
<entity name="contact">
<attribute name="fullname"/>
<attribute name="contactid"/>
<order attribute="fullname" descending="false"/>
<link-entity name="msdyncrm_segment" from="msdyncrm_segmentid" to="msdyncrm_segmentmemberid" alias="bb">
<filter type="and">
<condition attribute="msdyncrm_segmentid" operator="eq" uitype="msdyncrm_segment" value="bfc9d5d6-d6aa-e911-a859-000d3a3159df"/>

Now lets try to execute this first in web api.
Use below format : https://orgurl/api/data/v9.1/contacts?fetchXml=<xml here>

Now lets try to execute this using organization service, note that i am using paging here because the number of records can be more than 5000:

var fetch = @"<fetch version='1.0'  page='##pagenumber##' count='5000' no-lock='true'>
<entity name='contact'>
<attribute name='fullname'/>
<attribute name='contactid'/>
<order attribute='fullname' descending='false'/>
<link-entity name='msdyncrm_segment' from='msdyncrm_segmentid' to='msdyncrm_segmentmemberid' alias='bb'>
<filter type='and'>
<condition attribute='msdyncrm_segmentid' operator='eq' uitype='msdyncrm_segment' value='6f5846d5-e5ae-e911-a84b-000d3a802d92'/>

 var contactss = organizationService.RetrieveMultiple(new FetchExpression(fetch));                  
                        foreach(var contact in contactss.Entities)
                            var id = contact.ToEntityReference();


Apart from this fetch xml there is no way to retrieve members from the segment.  There are some issues and limitation i faced during this operation, will try to share them in another post.

I hope this helps!

Getting Anonymous Survey Response Consistently When Using Email Snippet – VOC

Quick Post.

Recently when designing/creating surveys in Voice Of Customer. I faced this issue of getting anonymous response if I am using email snippet from the survey. Expectation is when you use Email Snippet copied from a survey and put it in an email and send it. Customer fills the survey, you should have the customer/respondent details.


Which means you have to generate survey activities first and copy the direct URL from there and send it but its not what you would want to do every time.


This seems to be a bug in the Voice of Customer Version So please check if you are facing the issue and version is same. Please upgrade it to the latest version. 

Doing above resolved my issue and I could see the responses properly.

hope this helps!

How to display more than three columns in Dynamics 365 lookup view.

goutam dynamics

We know that we can display multiple column in the dynamics 365 lookup view but there is a limitation that you can only display maximum three column in the lookup view, though we can add multiple columns in the lookup view but you can see only first three columns in the lookup view. This is a limitation in Dynamics 365, Microsoft mentioned here.


Now how to display more than three column value in the lookup. You might be thinking to create a field where if we can store concatenating multiple fields value with some separator and add the field in the lookup view. So now to do this you may need to go for workflow /plugin/JS which is additional work.

Why not we go for calculated field where we can concatenate multiple fields and add the calculated field in the lookup view. I did the same with calculated fields…

View original post 98 more words

Email Template Demystified

Before I start this blog – I would like to mention that my previous blog on email template functionality How to insert dynamic values from custom entities in an email template – Microsoft Dynamics CRM has been a huge success and got 10K + views on both Dynamics Community and on my personal blog.

In this blog I am going to cover below:

  1. Using HTML in email template. I.e Adding a table, border etc.
  2. Adding images to email template, prerequisites, limitation etc
  3. Using desired fonts


Quick Tips:
1. Always use Internet Explorer when creating email template
2. Adjust IE settings to be in compatible mode with your CRM. (i.e adding CRM url to compatibility mode)


Using HTML in email template. I.e Adding a table, border etc..

The first question would be , what is the need to use html in email template? If you know email template has very limited option available from the designer such as limited number of fonts, Colors, font size etc. So using html to provide rich look to your email content can be a good choice. I have used them personally and customer loved them.

In this blog I will quickly create a basic html email template which will have a table with some information from CRM record and we will beautify it. Lets say i would like to create table with custom loyalty reward information. I can do something like below:

You can use any online html editor to create the required content like the one I used here: https://html-online.com/editor/  

Now save the template and go to a contact > activities > add an email and insert this email template:

This is just to show the capability. You can do a lot with HTML in your email template.

Adding images to email template, prerequisites, limitation etc.

Adding images to a email template has been very tidy work. However with correct knowledge its quiet easy.  Keep below in your mind when you want to add an image to an email template:

  1. Email template is not a container/storage. The image can only be referenced from a public source. Meaning image must be available/accessible public ally.  i.e located on sharePoint, company website, social network public image etc.
  2. You should set the image size using html rather then manually dragging the corners.

Lets take an example below. I would add an image to my email template showing my recent accomplishment which is available on my blog page:

Now if I need this image in email template. There are two options.

1. Copy the image directly by right clicking on the image from website or create an html using image. Open in browser and copy from there and paste in your email template:

however this method is risky as your image might vanish anytime.

2. Copy image hyperlink or image address and paste it and create html by proving the image source:

Save the template and insert into email and you will see image has been populated.

Quick Tip : You can store images as Image web resource within your dynamics CRM and use them like I have used above by simply taking the image web resource url.

Using desired fonts

Though template editor gives you very limited option on fonts and size. You can very add other fonts and desired size or any colour to your content.


Here is what you can do:

  1. Format your content on a word document and copy paste from there into your email template. It should retain the fonts, size and color.
  2. Set the formatting within your HTML.


<p><strong><span style="color: #ff0000;"> Rawish Kumar</span></strong></p>

I hope this helps!

Feel free to contact me in case of any difficulties.

Alternate Key Creation – Stuck On Pending Status

Alternate key is a great addition to useful features in dynamics crm. I have blogged about it here : Work With Alternate Keys

In this blog I just want to quickly show resolution when you create an alternate key and its corresponding job stays in “Pending” Status.

I.e Consider an example of my entity. On my customer entity I have a contact reference field  which I would like to be unique. hence I decide to create an alternate key. So I go to Settings > Customizations > Customize the System > Entity > My Enity > Key and create a new one by adding the contact reference field:

  1. Create new alternate key and add the required field:
  2. Click Save and Close. you will see job is created and shows you status. However even after waiting for minutes , it shows as “Pending” the expect status should be “Activated”.
  3. click on the job:
  4. But there also , you wont see anything 😦

Reason & Resolution

There are two possibilities:

  1. Since creating an alternate key essentially creates indexing on the table in the database. It will fail if duplicate records are already there.To remove duplicates either use advanced find to manually delete or update records or duplicate detection job to delete the record, see here :Set up duplicate detection rules to keep your data clean
  2. Other reason I can think of is the job is stuck may be due to some CRM Async Service. Try to delete and recreated the alternate key.
    If you are onpremise – you can restart async service and see if that works.

For me 1st one was the issue. I deleted the records with same contact reference number and it worked:

Now I could create the key and it was activated:

I hope this helps!

Populate Data From Child Record To Parent Record’s Quick Create Form In Dynamics 365

Populating data on forms in CRM is not a headache since you can do mappings for your 1:N record or simply do a Web API request using the parent lookup exist on the new form to retrieve the values from that record and set them on the current form.

However what if you have to populate data on a parent record form from a child record form? there is no out of the box functionality or script available for this. I digged in further and found below method. Its a rare but an important requirement. 

  1. I have an entity named “Potential Customer” which has a lookup of Contact along with some other fields such as name, contact ref number etc. My requirement is to pass name and contact ref from potential customer to contact on quick create form:
  2. Here are the two field below the parent contact lookup which I would like to be propagated to contact quick create form:
  3. To achieve this, I have used a concept of localStorage property.
  4. Create below javascript resource and add to your child record form( from where you will add new parent record) in my case its potential customer:
function SetLocalStorage(executionContext)

var formContext = executionContext.getFormContext();
var firstName = formContext.getControl("new_name").getAttribute().getValue().toString();
var refNumber = formContext.getControl("new_contactrefnumber").getAttribute().getValue();

localStorage.setItem("FirstName",firstName );
localStorage.setItem("ContactRef",refNumber );


In the code above I am simply retrieving the value from current record on load event and setting it to the localStorage. You have to set value using a key and the value. so from code below; FirstName is the key(using which we will retrieve the value) and firstName variable is the value.

localStorage.setItem(“FirstName”,firstName );

         5. Now add below code to your onload quick create form of the parent record in my case its contact.         

function RetrieveStorageValue(executionContext)
var formContext = executionContext.getFormContext();
var firstName = localStorage.getItem("FirstName");
var contactRef = localStorage.getItem("ContactRef");




In the above code i am simply retrieving the value set using localStorage.getItem(“KeyName”); and then setting it on the required fields.

Use this link explained very well by Neil on how to add javascript code to your form : JS Basics

So now when Click on the new button from the lookup dropdown to add a parent record , I get values populated:


Here you go! 

Few important points:  

  1. I don’t encourage using properties and methods which are not defined by/for Microsoft dynamics CRM.
  2. The data you add to localStorage doesn’t have expiration which means the data will be there unless you don’t clear it (hence in my code I clear it everything once I have  used the values)
  3. It is just one of the methods (sometimes referred to as “Unsupported”) to achieve this requirement.
  4. The above script is for Dynamics crm 365 v9 or above. Please use Xrm.Page instead of formContext if you wish to implement this in earlier versions.


I hope this helps! 

Search For Privilege Name Using Privilege Id

Quick post on how to search for privilege/permission name using privilege Id. You often in dynamics receive an error like below during your plugins or Web Api requests.:

“user is missing privilege ba09ec92-12c4-4312-ba16-5715c2cbd6da”

looking at the error, its difficult to tell what is the permission missing and on what entity.

Use this approach

All privileges are stored in an entity called privilege : Read more here.
you cannot see this entity in dynamics CRM front-end as its not available however you can easily query this entity using Web Api.

  1. Get web api url of your organization by going to Settings > Customizations > Developer Resources > Web API instance url:

    i.e. https://organizationname.api.crm8.dynamics.com/api/data/v9.1/

  2. Append this url with “privileges?$select=name” and put it in your browser: https://organization.api.crm8.dynamics.com/api/data/v9.1/privileges?$select=name


  3. hit Ctrl+F and search using id:


  4. Now we know the id refers to “PrvReadContact”. Go to the security role and assign appropriate read access on contact entity.

    hope this helps!