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.

Capturecrm2011

CRM2011 – Right layout

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

Capture11

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');
           elem.height('24px');
   });
}

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

CRM2016 – Right Layout

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
Xrm.Page.getAttribute("new_entitynameid").setValue(lookupReference);

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… 🙂

Problema

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.

Diagnosi

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

Soluzione

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.

CRM2013 – Multilookup: Modify the code CRM2011

I migrated the solutions from CRM2011 to CRM2013 but I found a big problem with Multilookup: It does not work…  I tryed to use the solution inside this post https://mscrmmindfire.wordpress.com/2014/05/20/crm-2013-manipulate-look-up-to-show-multiple-entity-record/ but does not work..

Customer type Lookups in Dynamics CRM have always been an interesting and powerful feature that allows you to associate records of multiple entities with entities like Cases, Orders, etc. PartyList Lookups are similar to Customer type lookups, except for the fact that it allows you to have access to a vast array of entities. They are generally available in Activities like Appointments, Phone Calls, etc.

Sometime or the other, you might have had the requirement to modify customer type lookup in CRM to restrict records to a particular entity. For example, you might want to restrict the end user from selecting Accounts while placing an Order from the “Customer” Lookup. Well, there’s a way to achieve that in CRM using JavaScript. It isn’t exactly a supported one. But chances of Rollups breaking it is very less.

img1

Things are a bit different in CRM 2013. In CRM 2011 and even CRM 4.o, the DOM was a litte bit different. But CRM 2013 has its own brand new DOM structure. So, the code differs from that of CRM 2011. If you simply want to get to the code to implement, you can move directly to the next section. If you want to know why that code is required, read on.

Consider we want to restrict the Cusom lookup to a specific entity, Account. If you’re using Internet Explorer, press F12 to open up the Developer Tools. Search for “new_testfield_i” and you’ll find something as follows.

img3

Now, this “new_testfield_i” is basically the magnifying glass image in the “TestField” lookup button. It consists some interesting properties that determine what entities will be displayed in the lookup form. However, we are interested in only a handful of them in order to get our job done. They are “lookuptypes”, “lookuptypeIcons”, “lookuptypenames” and “defaulttype”. Having a closer look at them pretty much explains what each property signifies.

So, now that we have identified what needs to be changed where, let’s get to the coding part of it. Basically, the idea here is to append “_i” after the Customer type lookup field name. Once you get that element, change its properties to get the desired result.

If you have followed the earlier section, you’d know why the following code snippet is required and what exactly it does. Just to be on the same page, the following code will allow only “Account” records to be displayed in the “Regarding” lookup field (in the Phone Call entity).

document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1:Account");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");

Well, don’t think it’s done yet! Although the above code might work most of the times, you might find it failing sometimes. Why? Because the entire DOM of Dynamics CRM 2013 is loaded in an asynchronous manner. Hence, the point where your script executes, the field “Regarding” might not have been rendered yet! Let’s add this small fix for it to work perfectly.

setTimeout(function() {
document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");
}, 1000);

Now, that was if you wanted to restrict a Customer lookup field to a single entity. What do you do if you want to allow multiple entities, and restrict only a few? It’s simple. See the following code to get it.

setTimeout(function() {
document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1,2");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif?ver=-475068199:/_imgs/ico_16_2.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1:Account,contact:2:Contact");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");
}, 1000);

The result now is as follows with Account and Contact being the only allowed Entities.

img5