XrmMtl http://xrmmtl.com Just another CRM Blog by Nicolas Plourde Wed, 05 Jul 2017 13:59:13 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.2 How to stop Quick Create form from saving http://xrmmtl.com/how-to-stop-quick-create-form-from-saving/ Thu, 30 Mar 2017 15:28:50 +0000 http://xrmmtl.com/?p=146 Continue readingHow to stop Quick Create form from saving]]> I ran into this problem today. I wanted to use the Quick Create form and do some custom validations in JavaScript. I could of done it by Plugin but I wanted the JavaScript look & feel.

Naturally, I tried context.getEventArgs().preventDefault(). Without success. The save did stop but the save button was disabled (to prevent another save on the stack, probably) and the loading dot were still shown above the form. It seems the function was not adapted to run into a Quick Create context.

I looked up on the Web and found a post on the CRM forum describing the problem and found a partial solution. So here’s the full solution. #unsupported

onSave: function (context) {

  if (!validateStuff()) { 
    setTimeout(function () { 
      top.document.getElementById('globalquickcreate_save_button_NavBarGloablQuickCreate').disabled = false;
      top.document.getElementById('globalquickcreate_loading_bar_NavBarGloablQuickCreate').style.visibility = 'hidden';
    , 0);

Basically, I do my validation then use the supported method. Then, I fix the save button and the loading dots. Also, I wrap everything in a setTimeout to delay the execution. Otherwise, the code is done before CRM’s.

In my professional opinion, the fact it’s unsupported doesn’t bother me because we are still using the supported way. Then, we are just adding a fix. If it does bother, add a try catch inside the SetTimeout. You are garanteed bullet-proof code that won’t ever crash.

How to automatically refresh a dashboard #unsupported http://xrmmtl.com/how-to-automatically-refresh-a-dashboard/ Sat, 18 Mar 2017 21:46:43 +0000 http://xrmmtl.com/?p=123 Continue readingHow to automatically refresh a dashboard #unsupported]]> Hi folks,

To refresh a dashboard, you can click on the button refresh. But, there is no supported way to refresh a dashboard automatically without refreshing the whole page.  Here, I’m offering you a simple solution to that problem.

First, create an html web resource. I named mine xrm_dashboard_autorefresh.html. It’s generic so I can use it in multiple places. In the content, copy and paste the following.  Then save and publish.

<script type=’text/javascript>
setInterval(function() {
},60 * 1000);

Second, open your dashboard. In the last row, add the web resource. Also, uncheck “Visible by default” to keep it hidden.

The script will use the same command as the Refresh button.

Save, Publish, go take a coffee.

Best way to find dirty fields http://xrmmtl.com/best-way-to-find-dirty-fields/ Mon, 03 Oct 2016 14:54:13 +0000 http://xrmmtl.com/?p=78 Continue readingBest way to find dirty fields]]> Hi folks,

Wondering what is that nasty field that kepts getting dirty when you open a form? Search no more and use:


It returns the data that will be send once you save the page.

"<account><primarycontactid type="2" name="Nick">646a9377-f184-e611-80c9-0050569307c5</primarycontactid></account>"

So, instead of looping through all fields and checking for who’s dirty. Do an indexOf on it:


CRM 2016 – + button not working on Opportunity Product subgrid on Opportunity form bug http://xrmmtl.com/crm-2016-button-not-working-on-opportunity-product-subgrid-on-opportunity-form-bug/ Tue, 16 Aug 2016 15:50:44 +0000 http://xrmmtl.com/?p=64 Continue readingCRM 2016 – + button not working on Opportunity Product subgrid on Opportunity form bug]]> Hi folks,

A really long post name for a simple problem. Another bug caught my attention today and I was so amazed by it I thought it deserved a post.

If your ‘+’ button on the Opportunity Product subgrid on the Opportunity product doesn’t work anymore, change the name of the grid back to opportunityproductsgrid.

opportunity product subgrid  opportunity product subgrid 2

That’s it. Another weird bug solved.

Solution was found here on the Dynamics Community forum: https://community.dynamics.com/crm/f/117/t/176528?pi51685

CRM JS – Missing accents / Accents manquants http://xrmmtl.com/crm-js-missing-accents-accents-manquants/ Wed, 22 Jun 2016 21:07:15 +0000 http://xrmmtl.com/?p=50 Continue readingCRM JS – Missing accents / Accents manquants]]> This is a little reminder for those who are making alerts and notifications in another language. If you ever see your accents or other foreign symbols being replaced by ‘?’, the fault is in the encoding of your javascript file.


Open Notepad++ and change the Encoding.


CRM 2016 – Phone Call: blank notification http://xrmmtl.com/crm-2016-phone-call-blank-notification/ Wed, 22 Jun 2016 19:08:12 +0000 http://xrmmtl.com/?p=38 Continue readingCRM 2016 – Phone Call: blank notification]]> Hi folks,

Today, I’m sharing a fix for a bug I found in my CRM. Basically, I opened the Phone Call form and found out a blank error notification. There was no business rule and no javascript in the form.

May9 1

After some research, I found this post describing the issue. But no fix. Since it was still not solved after the 8.1 update, I decided to make this little unsupported piece of javascript. I’m hoping it will be fixed in the next update.

[code lang=”js”]function OnLoad() {
if (!window.parent.$(‘span#Notification0_text’).text()) {
var notificationId = window.parent.$(‘div#Notification0’).attr(‘notificationid’);

if (Xrm.Page.context.getUserLcid() == 1036) {
Xrm.Page.ui.setFormNotification(‘Au moins un destinataire est marqué "Ne pas autoriser" les appels téléphoniques’, ‘ERROR’);
else {
Xrm.Page.ui.setFormNotification(‘At least one recipient is marked as "Do Not Allow" phone.’, ‘ERROR’);


CRM 2016 – SetDisabled is not working http://xrmmtl.com/setdisable-is-not-working/ Mon, 13 Jun 2016 16:10:52 +0000 http://xrmmtl.com/?p=27 Continue readingCRM 2016 – SetDisabled is not working]]> Hi folks,

Today, I found  a new bug in CRM.


I have a form with two sections. Under some circumstances, I show one and hide the other. That part is working.  In both of those sections, I have a field called xrm_field. Again, under some circumstances, I want to disable that field doing the followning:

[code lang=”js”]Xrm.Page.getControl(‘xrm_field’).setDisabled(true);[/code]

While testing my code, I discovered that when the second section is hidden, the field is disabled, but when the first section is hidden, the same field is not. Therefore, I made sure that nowhere in my code I was enabling/disabling it again.

Résultats de recherche d'images pour « meme question mark »

The problem

To understand why this is happening, I dug into MSCRM javascript. What I found out made me shudder. In a list of all the controls, I saw this:

  • xrm_field
  • xrm_field1

So I added:

[code lang=”js”]Xrm.Page.getControl(‘xrm_field1’).setDisabled(true);[/code]

and it worked!


Against all odds, the MVC pattern that is working with the attributes, is not with the controls.

So, until this is fixed, we’ll have to remember to set the “other” control too.

Hope this helps!

Optimal settings for IE http://xrmmtl.com/optimal-settings-for-ie/ Thu, 09 Jun 2016 20:18:24 +0000 http://xrmmtl.com/?p=22 Continue readingOptimal settings for IE]]> Even if I use Chrome for most of my development (#chromeisawesome), all my clients require their CRM  2016 to run with IE.

Résultats de recherche d'images pour « internet explorer meme »


This is the best list I have found so far. It includes:

  • IE default settings
  • Antivirus exclusions settings
  • Some tips regarding third parties


CRM 2016 – Update lookup field bug http://xrmmtl.com/crm-2016-update-lookup-field-bug/ Wed, 01 Jun 2016 17:25:52 +0000 http://xrmmtl.com/?p=9 Continue readingCRM 2016 – Update lookup field bug]]> I am reposting this post that I found on Dejan Dular‘s blog.

That bug almost made me crazy. After two hours of Javascript debugging I finally realized what was going on and when I entered the right keywords in Google, I found that post:

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


In addition, this error pop-uped in the console: Uncaught TypeError: Cannot read property ‘UnselectRecords’ of null.

In the end, I was able to update a field on the OnLoad event of a subgrid.

Elegant way to set a lookup http://xrmmtl.com/elegant-way-to-set-a-lookup/ Wed, 01 Jun 2016 15:53:23 +0000 http://xrmmtl.com/?p=7 Continue readingElegant way to set a lookup]]> Hi folks,

I found out an elegant way to set a lookup. Here’s the old way:
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = 'fc62d5f4-a589-452d-b134-aaa080c0d75a';
lookup[0].entityType = 'contact';
lookup[0].name = 'Nick Plourde';

Here’s the nicer way:
var lookup = [{
id: 'fc62d5f4-a589-452d-b134-aaa080c0d75a',
entityType: 'contact',
name: 'Nick Plourde',

type: 'lookup'

And don’t forget you can still this:


That’s all!