Add a custom button to a CRM 2011 form

I’ve seen a number of examples of how to create buttons on a CRM form. Unfortunately a lot of them rely on the crmForm.all property, which is deprecated and expected to be removed in the next version (CRM 2013).

The following code shows how to create a button that works in CRM 2011, but which uses none of the legacy features from CRM 4.0. The code uses some unsupported methods of manipulating the DOM, so if it breaks, you are responsible for fixing it.

// CRM 2011 Style Button
// Creates a button from a form field
function ConvertToButton(fldName, btnLabel, btnWidth, evt) {
    var btn = '<button class="ms-crm-Button" id="btn_' + fldName + '" onmouseover="Mscrm.ButtonUtils.hoverOn(this);" onmouseout="Mscrm.ButtonUtils.hoverOff(this);">' + btnLabel + '</button>';

    var ctrl = null;

    try {
        ctrl = Xrm.Page.ui.controls.get(fldName).get_chromeElement()[0];
    } catch (e) {
        ctrl = Xrm.Page.ui.controls.get(fldName)._control.get_element();
    }

    // Add the new button
    ctrl.innerHTML += btn;

    // Hide the textbox
    ctrl.children[0].style.display = 'none';
    ctrl.children[1].style.display = 'none';

    // Hide the label
    Xrm.Page.ui.controls.get(fldName).setLabel('');

    // Add Event to the newly created button
    ctrl.children['btn_' + fldName].attachEvent('onclick', evt);

}

Please post any bug-fixes, problem reports or enhancements in the comments below, and I will try to keep the post updated.

Re-enable Copy/Paste in Web Resources in CRM 2011

If you have added a web resource to a form that includes ClientGlobalContext.js.aspx, you may notice that your copy/paste functionality is now missing. This is due to the event handling within the ClientGlobalContext javascript.

To disable the CRM event handling, simply include and call the following function.

// Function that allows copy-paste functionality 
function AllowCopyPaste() {
  document.oncontextmenu = null;
  document.onmousedown = null;
  document.onselectstart = null;
  try {
   Sys.UI.DomEvent.clearHandlers(document); // try the CRM 2011 Polaris way of removing events
  } catch (err) {
  }
 }

Note that this function should never be called from Javascript that executes within the context of a CRM form, as it WILL disable functionality on the form. It should only be used in external web resources that use the global context.

I recommend calling it as soon as possible after the ClientGlobalContext is included.

This code works in all versions of CRM 2011, including Polaris. Hopefully, it should also work in Orion (CRM 2013).

Getting Notifications to work in CRM 2011 UR12

If your CRM 2011 online instance has recently been upgraded to CRM 2011 UR12 (Polaris), you may have noticed that a few things don’t work as well in Javascript as they used to. One of the major annoyances is that the notification code posted here stopped working.

I investigated the problem, and found that the AddNotification function is now no longer attached to the element “crmNotifications”, but to a separate object within the Javascript object model. Below is an updated version of the code that should work with Polaris.

addNotification = function (message, level) {
 var notificationsArea = $find('crmNotifications');
 if (notificationsArea == null) {
 alert('notifications not found');
 return;
 }
if (level == 1) { //critical
 notificationsArea.AddNotification('mep1', 1, 'source', message);
 }
 if (level == 2) { //Info
 notificationsArea.AddNotification('mep3', 3, 'source', message);
 }
 if (level == 3) { //Warning
 notificationsArea.AddNotification('mep2', 2, 'source', message);
 }
 if(message == "")
 {
 notificationsArea.SetNotifications(null, null);
 }
 }

The changes can be found on the second line, which uses an internal undocumented function $find. Having said that, the document.getElementById function is also an unsupported method, so if it didn’t work before – and does now – you’re in the same situation as you were previously.

Useful Resources

http://blogs.msdn.com/b/johnsullivan/archive/2011/11/02/crm-2011-custom-form-notification.aspx

http://marcoamoedo.com/blog/show-custom-warning-messages-on-microsoft-dynamics-crm/

Ultimate Google Analytics plugin now hosted on Github

I’ve tidied up a few of the small bugs mentioned on the support forum at http://wordpress.org/support/plugin/ultimate-google-analytics, so the code should contain a few less niggling little problems.

I’ve also moved development over to github, in case anyone else wants to help out with the maintenance burden. The code can be downloaded at https://github.com/robotii/ultimate-google-analytics.

Please feel free to clone the repository and send pull requests if you do anything interesting.

Synopsis of Traffic to this Site

There are two main types of traffic that you can get to your site.

The first is search engine traffic. This is where your site has come up in the search engine listings for a particular keyword, and someone has clicked on the result, hoping that the page is going to be of use to them.

The second is where you have a link on another site, that may not be under your control. These are usually referred to as referral links.

I’ve noticed that the referral links tend to provide more value in terms of more pages visited on my site. The Google listing provide more traffic, but of slightly less quality.

Note that I’m measuring quality by the number of pages per visit, which is mainly due to the fact that my main goal is not to get money off people, but simply to put this stuff out there and see what happens. Interestingly enough, the BBC site, although providing fewer “hits” than most other sites, also provides more pages viewed per visit than either Google, Bing, Yahoo or other referrals. I’m guessing that this is due to the BBC attempting to provide high quality links, and hence the trust factor on BBC links is much higher than for other sites.

The biggest spike in BBC traffics came around August last year (2011), but doesn’t seem to correspond to any post or activity on my part, so I’m still not really clear as to what happened there. It also seems to have died off, so I’m presuming that it was time dependent.

Google traffic has steadily increased on the site over the last 12 months, while a minuscule part of the traffic comes from Bing, Yahoo! and Ask. The biggest referrer by far is artofmanliness.com, which accounts for almost as much traffic as Google, but results show that people don’t spend any more time, or visit any more pages than they do when coming from Google. The biggest page by number of hits is my Best Man’s Speech, written for Richard‘s wedding, and has consistently been high since it was put up there. It accounts for the majority of my traffic.

All in all, as visitors are still coming here, and in increasing numbers, despite the low level of posts, I think we are doing OK.

Epic fail!

image

Came across this in Paddington Street Gardens, London

Buying an Android Tablet

If you want to get an Android tablet, you should look out for the following:

Capacitive touchscreen – this is a must, or you will hate using it. Don’t even look at it if it says resistive touchscreen. Seriously.

Android version 3.0 (also known as Honeycomb) or Android 4.0 (aka Ice Cream Sandwich or ICS), as previous versions will not run apps designed for tablets. Again, pretty essential. Prefer version 4.0 if possible.

Android Market (or Google Play as it’s now called) – this lets you install apps easily. Some of the tablets don’t support it, which makes it a pain to load apps on them. Another essential.

RAM – preferably 1GB, although 512MB would be acceptable if everything else looks OK. Anything with less than 512MB is not worth getting, no matter how good it looks.

Storage – 8GB or 16GB most likely. Can go up to 32GB, but that’s beyond my budget too! Recommend that you make sure it has a storage slot and not worry too much about this.

MicroSD slot – a lot of tablets will have this, typically worth it if you want to put your music on the tablet. Internal storage size is less important if you get one of these slots, as the cards are usually under £20, and you can get one if you need one.

Size. Usually either 7″ or 10″. Take your pick. I would recommend the bigger screen, unless you have a particular reason for getting something smaller. Worth going into a shop with them in and having a play to see which you like best.

HDMI - used to connect to your TV or some new monitors. You would probably need a cable, as it’s different from the normal HDMI cables. Again, you have to decide if you want to connect to the TV.

BTW, if you want a 7″ tablet one of the best on the market (if not the best) is the HTC Flyer @ £218.12

Entitlement – No Need to Justify Yourself?

Entitlement - Taking up two parking spacesI have increasingly noticed a trend on social networking sites, where people post up links to various other sites and expect that they can commandeer the attention of their supposed friends or followers. In one recent particular case, the link in question was to a 30 minute video.

Now there’s nothing wrong with posting links to 30 minute videos, or even longer if you can find them. The problem occurs when someone then asks why they should spend 1/2 an hour of their time watching this video. Some people become quite indignant when asked to justify why you should spend your time in a manner proscribed by them. Instead of posting up a link to a video with no explanation as to why it’s worth watching, try connecting with people and telling them why they should care.

To do other than the above is begging the question of relevance. If you really can’t think of the reason that someone should be following the link, then I would question why you want to do it in the first place. If it’s because everyone else is doing it, I would question the value of it immediately. The wisdom of crowds can very easily turn into the folly of crowds.

The bottom line is that you do need to justify why you expect someone to take time out of their day, and the bigger the chunk, the more justification that is required. For instance, if you link to a 3 minute video, you may want to tell them it’s funny, and that would be sufficient. For something longer, it might be wise to let people know what to expect. 

If you are thinking that this post is aimed at you, then you are almost certainly correct. The question is, what are you going to do about it?

Picture is from http://www.justinbuzzard.net/2012/01/30/dont-confuse-entitlement-with-salvation/ 

Update to Ultimate Google Analytics WordPress Plugin

I really like the Ultimate Google Analytics plugin for WordPress. It does exactly as I need it to do in terms of ensuring that the Analytics code is embedded in each page. Unfortunately it hasn’t been updated since 2008, and the code is a little out of date.

I have taken the liberty of updating some of the code, and have posted it here for you to share. This adds in the most recent GA javascript, allowing it to load asynchronously and hence speed the page load time. I am keen to make further changes, but I have contacted the author of the original code to see if he is willing to pass the maintenance burden onto myself.

The code is compatible with any version of WordPress from 1.5 to 3.2.1 and probably beyond. That said, please leave a comment if you do have any problems with it.

Download: ultimate_ga_1.6.1.zip

Just do it (again)

Plan to throw one away, you will anyway

It is a well known axiom in computer science that the first system or prototype you develop will need to be discarded. There are a number of factors that can contribute to this. Firstly, the understanding you gain on what the system needs to do from actually building the system quite frequently means that it would make more sense to completely redo the project or code.

Secondly there could be some improvements that you could make after seeing the system in operation, ranging from performance optimisation to additional features that would be useful.

There are doubtless many other reasons that could be brought up. However, I’d like to point out a couple of points on this.

It is not always a bad thing to have to start again. Sometimes this is exactly what is needed, although it is far from the axiomic truth that is is purported to be.

System designers and project managers rarely take this into account when planning and designing new systems. This can lead to project overruns, in terms of budget, time and lead to low quality deliverables.

Agile solutions are proposed as an answer to this, but I remain unconvinced. I definitely see these techniques as being better than the traditional waterfall methodology for a large proportion of projects, but I am convinced that there needs to be a fundamental change in the way we develop and manage large software products.

I will hopefully get round to posting my thoughts on how this can be achieved in the near future.

I would appreciate any comments on this subject.