March 23, 2016

Error when opening an inactive entity

After migrating from CRM 2015 to CRM 2016 I experienced strange behavior at some inactive entities. Immediately after opening it I got an error:

The object cannot be updated because it is read-only

Wait what? I did not change any data! Why this error? Disabled all javascript, disabled all plugins, the error was still there.

We introduced business process flow some months ago in this entity. The old entities had no process and stage ID defined. CRM 2016 wants to fix this immediately when dealing with an entity that has no process or stage defined and sets the default values.

But there is a bug in CRM. The update is made on inactive entities as well. Thus the error.

The only solution is to update the values directly in the database: 

UPDATE ENTITY SET ProcessId = PROCESSGUID , StageId = STAGEGUID  WHERE (ProcessId is null or StageId IS NULL) AND StateCode = 1

March 5, 2016

Do not name the action parameter "Error"

If you create an output action parameter named "Error" and you assign a value to it using "Assign Value step" the action will be published normally, but when trying to execute it, you will get the message:

The following errors were encountered while processing the workflow tree:
'DynamicActivity': The private implementation of activity '1: DynamicActivity' has the following validation error:   Compiler error(s) encountered processing expression 

Just rename the parameter and the error will be gone.

March 3, 2016

CRM 2016 Update lookup field bug

I encountered a strange behavior after upgrading on premise CRM 2015 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