CRM 2016 – Get all activities related with a user with C#

Today I need to get all activities related with a specific user. The way it to easy: We can use FetchXM or Query Expression. I usually prefer use Query Expression.
The code is easy:

private List<Entity> GetAssociatedActivities(EntityReference regarding)
            QueryExpression query = new QueryExpression { EntityName = "activitypointer", ColumnSet = new ColumnSet(new string[] { "activitytypecode" }) };
            query.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, regarding.Id);
            query.Criteria.AddCondition("statecode", ConditionOperator.NotEqual, 1);  //ignore completed
            EntityCollection collection = _sdk.RetrieveMultiple(query);
            return collection.Entities.ToList();

That’s all.

CRM2016 – Wrong height Layout inside a WebResource on Form

We have a HTML Page as a webresource inside our CRM. In this webPage there are two dropdownlist. We need to manage a Due date.
This was created in the past for CRM2011 and all layout worked always in right way.


CRM2011 – Right layout

We upgrade our CRM to CRM2016 and we start with layout problem:


CRM2016 – Wrong layout


I must insert this piece of code inside my webresource:

if (typeof parent.$ !== 'undefined') //Check for CRM2011 version. Work only on CRM2015/CRM2016
   parent.$( document ).ready(function() {
           var elem = parent.$('#WebResource_duedate');

This code works on DOM directly and change the height. The result is:

CRM2016 – Right Layout

CRM2013 – Save and refresh an entity without postback

Today I had a strange problematic for my client: I needed to update an hidden field without that the user niticing it. I found a solution on this blog:

function SaveAndRefresh() {

Thanks a lot for this great solution!

CRM2016 – Check if Turbo Forms are enabled

Inside our form we need to check if “Turbo Form” is enabled or not. There are an usupported way to check this:

var turboFormsEnabled = Xrm.Internal.isTurboForm();

Xrm.Internal function: this function calls Mscrm.Utilities.isTurboForm which then checks window.IsTurboForm; if window.IsTurboForm is undefined, returns false, otherwise true.

CRM2016 – Update lookup field bug

2007_microsoft_dynamics_crmI encountered a strange behavior after upgrading on premise CRM 2013 to 2016 version.

In the account form after I set the value of the custom lookup field (lookup to custom Country entity) I got javascript error:

SCRIPT5007: Unable to get property ‘trim’ of undefined or null reference

After some hours of debugging I removed all javascript code. Then I copied the example from SDK, the error was still there.

Investigating the setValue method I discovered, that something like “internalOnChange” was called. I suspect this method was called because there are some filtered lists in the page that depend on the value of this field.

Long story short, there are two ways to fix this:

Method 1:
Go to Settings-Administration-System settings. All the way down at the end of the page enable “Use legacy form rendering”.

This will definitely slow down form loading.

Method 2:
The code deep down in the out-of-the-box CRM javascript libraries the script wants to parse the attribute type, but it is not there. The value should be “lookup” and you should pass it in the object when calling setValue.

//Create the lookup value object
var lookupReference = [];
lookupReference[0] = {};
lookupReference[0].id = "{a0c68c89-9752-e311-93f9-00155d78043f}";
lookupReference[0].entityType = "new_entityname";
lookupReference[0].name = "Display name";

//Magic happens here
lookupReference[0].type = "lookup";

//Update the lookup field

CRM2016 – Two Options field bug

Today I found a bug inside CRM2016; I upgraded CRM2013 to CRM2016 and I have some Form Legacy.

On Form I have a field with name “Select Product”. This field has two value to choose:

  1. Existing
  2. Write In


When I open this form, I have always “FALSE” as default value:


I tried to delete and re-create but I always have the same problem. I don’t find a solution but I found a workaround in javascript: I created a method to manually force the change value:

attribute attr1 = Xrm.Page.getAttribute("nameattribute");
if (attr1 != null)


I don’t understand if this is a CRM2016 problem or it is my problem…


CRM2011 – Errore: The view or chart specified in the dashboard definition is not valid for the specified record type “Entity”

E’ la terza volta che ho questo errore ed ogni volta mi dimentico sempre come risolverlo. Ho deciso di scrivere un post e *tatuarlo” in internet… 🙂


Quando “linko” una nuova webresource con un FETCH XML custom ad una entity (che sia linkato come webresource nel Navigation Pane o come IFRAME direttamente nell’entitĂ ) ricevo il messaggio di errore in oggetto.


Questo problema è dovuto al GUID errato inserito per la DefaultView. Il GUID inserito è corretto ma il tipo di vista selezionato non è DefaultView.


Aprire dalla Solution l’entitĂ , selezionare la sezione Views, selezionare il link della Default View.

Dal link estrarre il GUID ed inserirlo nella nostra WebResource.