Skip to main content

Posts

Showing posts from September, 2014

Preventing the Dynamics CRM Outlook add-in from creating contacts, forever

It's an ongoing issue here wherein a misconfigured / misbehaving Outlook client sometimes creates duplicate or redundant contacts in our CRM, and I've seen many blog posts and forum threads discussing the various ways of getting around it.  Unfortunately they all require user-specific configuration, whereas I wanted to banish the problem across the board once-and-for-all.  Completely by accident I came across a solution, which in retrospect is extremely obvious and I'm rather embarrassed that I didn't figure it out sooner!

It all hinges on the fact that the Dynamics CRM website will execute javascript on the form, and of course the Outlook add-in will not, as no form is loaded (although there is a way to get one, which is covered here too).

Add a boolean field to your contact entity called "Permit Creation", which defaults to no.
Add it to the contact form, but mark it as hidden.
Add the following javascript to the contact form in the page load event:

if(!Xrm…

jQuery ajax error logging on the server with log4net

This post is based on Toby Gundry's post on the same technique, but adapted for logging jQuery ajax errors (although I added a few extra things too).

In your Javascript:

    $(document).on({
        ajaxError: function (event, jqXHR, ajaxSettings) {
            var err = "Location: " + document.location.href + "; ";

            if (jqXHR)
            {
                err += "Status: " + jqXHR.status + "; ";
                err += "Text: " + jqXHR.statusText + "; ";
            }

            if (jqXHR.responseJSON) {
                err += "Message: " + jqXHR.responseJSON.Message + "; ";
                err += "Stack Trace: " + jqXHR.responseJSON.StackTrace + "; ";
            }

            if (ajaxSettings) {
                err += "Data Sent: " + ajaxSettings.data + "; ";
                err += "URL: " + ajaxSettings.url + "; ";
            …