CRM, JavaScript, Web Services

Using Xrm.WebApi in popup Window

I wanted to use Xrm.Webpi methods inside a web resource loaded into a new window however I ran into a limitation on how CRM implements their internal methods.

The following describes how I attempted to troubleshoot this issue and how I eventually implemented a work around

Continue reading


Duplicate Detection not showing any results

I was working on an issue with Duplicate Detection reported by a customer. They had duplicate detection enabled on Contact with rules detecting records with the same firstname and lastname.

The steps they were following were:

  1. Create a Contact: John Smith
  2. Create a second John Smith Contact

The problem they were reporting was that when they entered the second “John Smith” the duplicate detection dialog was appearing; however, the dialog was not showing the potential duplicates.

Now because the same user was creating both Contact records, we thought it wasn’t a security issue, but we were only partially correct – it was a security issue but not related to Contact

The underlying problem was that the Duplicate Detection Rule was created in a different Business Unit and the user’s Security Role didn’t have Organisation-level read for Duplicate Detection rules. So CRM knew that a duplicate existed, but the user didn’t actually have permission to view the results.

The fix was simple: extend the user’s security role to include Organisation-level read permission of Duplicate Detection Rules.



CRM Plugins – Input Parameters and Early Binding

I recently came across this problem looking at a CRM instance that had been upgraded to use early-binding. They had done something like below:

var accountInputParameters = ((Entity)context.InputParameters["Target"]).ToEntity<Account>();

This takes the InputParameters (which is of type Entity) and then bound it to the Account early-bound type.

While this seems like a good idea on the surface, as it allows all the fields of the Account to be accessed using strongly typed properties, the customer reported some strange behaviour on their Accounts.

Continue reading

CRM, JavaScript

Some helpful CRM 2016 Bookmarklets

I’ve been working in CRM Online (2016) a little for the past few weeks and I found these little bookmarklets to be helpful.

For those that don’t know, a bookmarklet is a snippet of JavaScript that can be saved as a Bookmark in Chrome, IE or Firefox. By prefixing your JavaScript function with javascript: you’re telling the browser to execute JavaScript rather than go to a particular URL

So far I have bookmarklets to

  • Print the current entity’s schema name
  • Print the current entity’s ID
  • Reopen the current entity’s form

The Print ones are quite nice because I used CRM’s in-built notification system.

Continue reading

JavaScript, SharePoint, Web Services

Using SharePoint REST to create a folder

I was tasked with creating some folders in a Picture Library and I thought that this would be the perfect opportunity to use the SharePoint 2013 REST API for the first time.
It was actually quite easy:

function CreateFolder (){
    var url_web;
    var pictureLibrary
    var folder_name;
    var folder_path;

    url_web = _spPageContextInfo.webAbsoluteUrl;
    pictureLibrary = 'Pictures';
    folder_name = 'jasonscript';
    folder_path = pictureLibrary + '/' + folder_name;

        'url' : url_web + "/_api/Web/Folders/Add('"+ folder_path + "')",
        'type' : 'POST',
        'headers' : { 
            'accept' : 'application/json; odata=verbose', 
            'content-type' : 'application/json; odata=verbose',
            'X-RequestDigest' : $('#__REQUESTDIGEST').val()
        'success' : function (evt){
            // folder has been created
        'error' : function (jqXHR, textStatus, errorThrown){
            // handle the error

The biggest problem that I had was that I found that the Add method seems to only accept values wrapped in single quotes.
I typically use single quotes to define my strings

    var myString = 'wrapped in single quotes';

However, when I tried this

    url_web + '/_api/Web/Folders/Add("'+ folder_path + '")'

I kept getting ‘bad request’ errors. Switching the quotes around resolved this problem.

    url_web + "/_api/Web/Folders/Add('"+ folder_path + "')"