Performance Markers…who knew??

So this might not be news to some of you, but I stumbled on an interesting tool in CRM 2013 this morning.

In the course of my job, I have to capture a lot of screen shots, so I use a tool called SnagIt from Techsmith.  SnagIt is a great tool, and I highly recommend it, but that’s not the point of the story.

I have SnagIt configured to start a screen capture when I select Ctrl-Shift-Q from the keyboard.  This morning I was looking at something in CRM 2013 I wanted to capture and mark up. I did the Ctrl-Shift-Q and to my surprise…this Performance Markers window popped up in CRM?

At first I missed it because SnagIt was capturing the screen without it, but when I exited the SnagIt capture, there it was.

Looks like it’s showing the load times for the various functions on the page, and could be very useful in the future.  I searched, but all I could find was that you can use Alt-Shift-Q or Ctrl-Shift-Q to make the window appear.  I can’t find any other documentation on how to use it, maybe someone else has seen it somewhere?

Enhanced SLA’s in CRM 2013/2015

I’ve been reviewing the new SLA capabilities in CRM 2015, but I’ve got to go through CRM 2013 first because we are still on 2011, which was upgraded from 4.0.

I had to build an entirely custom SLA system (although we call it TRT for ‘Target Response Time’) because this was not available in 4.0/2011.  

This new 2013/2015 system looks cool, and I like the idea of a timer control on the case to show the time left before the timer expires.

One of the main things I see in the new one is the ‘pause’ feature, which can come in handy.  Because we offer 24/7 support for several of our products, but after hours the support is done by a support analyst on-call, we have to manually calculate the the target for new cases that come in after 8pm ET, or on a weekend.  

Example:  Priority 3 case comes in at 9:00PM on a Wednesday night.  Target Response/SLA is 4 hours, but because it’s after hours we don’t set the target for 1:00am, we set it to 12 noon the next day because we open support at 8am the next day.

Wondering if CRM SLA system can work with this?  Guess I will find out as I research this new feature.

Starting a new CRM project

Haven’t written anything here for quite a while, I’ve been busy working on a customer facing portal project with CRM on the back end, and using ADXStudio CMS on the front end.

Now that is mostly finished, I’ll be moving on to upgrade 2 separate instances of CRM from 2011 to 2013, and probably 2015 as soon as it comes out.

Already noticing a lot of changes to the UI that will be very difficult for the end users to adapt to.  The lack of navigation on the left side to get to related records, is weird.  I’m reviewing a tool from called the SmartBar.

Should be an adventure!

URL Encoding in CRM 2011 Views – Bug and Workaround / Fix

In our internal CRM org that is used for customer service, I developed a custom entity called Case Cloud Attachments to use to compile all attachments for a case into one centralized place.  Those attachments could have been done from CRM, uploaded through our portal, or sent in to a related email on a case.

In this custom entity record, there is a single line of text field with URL format.  This URL would point to the file that was uploaded to Azure blob storage.  This record is then related to a parent case so while reviewing the case you could see all attachments in one place.


Notice that as you mouse over the link, the URL is messed up and an http:// has been pre-pended to URL.

When we were using Update Rollup 11 (UR 11) in our CRM on premise deployment, this URL would still work, even though the display of the URL in the view showed incorrectly.

All was well and nobody noticed…until I upgraded to Update Rollup 13 (UR 13) this past week.  Suddenly, it stopped working, and if you clicked the link in a View, it would try to load the bad URL… and of course it failed.

One interesting note: If you open the full record and click the URL text field on the main record form, the link would open just fine in UR 13.  It only failed to open if you clicked it in the view.

The Workaround / Fix:

It turns out that this is a bug in CRM views, and a bug in the way I was writing text to that field.

Because many of the email attachments that were coming in to cases were in-line images embedded in the email, they don’t have an actual file name.  So the Email system assigns it a random name and number like image001.png, image002.jpg, etc.

At the same time it also wraps this name in Braces { }.  That turned out to be the problem, because a URL should not have braces in it.  They need to be URL encoded to:

%7b – open brace {

%7d – close brace }

For some reason UR11, probably because it was IE specific browser only, was able to translate these to the appropriate URL encoding and open the URL.  Since I am sure that the JS code for views had to be modified in UR 12 and also UR 13 to support multiple browsers, suddenly the URLs were no longer being translated correctly.

I modified my plugin to use the .Net function HttpUtility.UrlEncode to properly encode the URL before I write the record, and that fixed it.

It’s still a bug in the way views work in CRM grids, but at least I have a way to prevent it in the first place.  I opened a support case with Microsoft and was able to reproduce this problem with them, even on a standard entity like Account.  They are reviewing it to see if it can be fixed in a future rollup.



Managing CRM 4.0 Plugins converted to 2011

As part of my 2011 upgrade from 4.0, I was able to setup a new ‘clean’ server this past week, and discovered something very strange that is a bit disconcerting. All of my 4.0 Plugins seemed to convert to 2011 OK, but for some reason if you try to manage/change them in the new 2011 Plugin Registration tool, you get a lot of errors.

As part of my 2011 upgrade project, I am re-writing all of my plugins that work with data, but I was leaving all the ones that created custom workflow items alone.  However, one of my earlier plugins had some auto-numbering code for entities that needed a number, and some custom workflow items.  So what I planned to do was to just un-register the steps that did the auto-numbering, and leave the other stuff alone.

When I went into the 2011 plugin registration tool, clicked the plugin and steps, clicked ‘unregister’…and got a bunch of error messages.

Some research (i.e. Google searches) revealed that is was having trouble because it was compiled under 4.0, but the server was a new, clean 2011 server that had never had 4.0 on it.  SO the solution was to register some of the 4.0 assemblies in the GAC on the new server.

So you need to get these assemblies from a 4.0 server and register them on the 2011 server.

Note: After registering them, I also needed to reboot the server. 

gacutil /if System.workflow.activities.dll
gacutil /if Microsoft.crm.sdk.dll
gacutil /if Microsoft.crm.sdktypeproxy.dll

This seems to work, but really bothers me that I had to do this. It was not truly a complete upgrade from 4.0.  Granted, if I didn’t have any plugins, this wouldn’t be an issue, but I doubt there are too many deployments that don’t have at least one.

2011 Plug-in Development and Debug Workflow Tips

Just started a major part of a 4.0 to 2011 conversion and began to re-work my Plug-ins.  I did this for multiple reasons, but the main one is that I wrote a lot of 4.0 plugins on the fly while I was learning how to write them.  Needless to say, a lot of my code was not very efficient and needed some re factoring.  Lots of code duplication across multiple projects.

The first thing I did was to install the CRM VS2010 developer extensions and use them to create my Plugin project from scratch, along with adding a CRMPackage project to deploy the plugin.

I really like being able to browse the entity in CRM Explorer, right-click and select to “Create Plug-In”, select the type, etc.  It creates all the basics for you.  Sweet.

The first time you have all your Plug-ins and steps/messages (Post Create, Post Update, etc.) defined, you can then go to the CrmPackage project and deploy the Plugin.  It sets everything up for you, so you don’t have to go into the Plugin registration tool and manually add the plug-in, steps, images, etc.

However, I also saw that if you are just working in the code making minor changes, that this ‘deploy’ step can take some time, slowing down your development.

So I wanted to see if I could just update the Assembly DLL directly, since my steps and target images weren’t changing.  I was just adding new functional code or fixing bugs.

This can be done, but it’s tricky.  The first couple of times I tried it, the Plugin Registration Tool would lock up tight requiring me to kill it in Task Manager.

Part of the problem is that in order to copy the .PDB debug symbols to the serverbinassembly directory, you have to issue an IISRESET in the build process.

I do this as a post-build event command line, followed by a copy of the .PDB files to the directory.  I also copy the DLL to a local directory that I can point the Plugin Registration Tool at.

The side effect of this is that the Plugin Registration tool loses its mind, and apparently a cached connection to the server.  If you just jump over to it and try to update the assembly with the Update Button, it will lock up.
The solution…Refresh first.
By refreshing, it takes an extra few seconds as it reconnects to IIS, but that’s what you need to do to keep it working.  After that you can click Update, point it to your re-built DLL file, and you’re all set.
In 4.0 i used to be able to just Update the Assembly directly, and that process would take the extra few seconds while it reconnected to IIS, but that now causes a lockup.  No big deal, but was pretty annoying the first few times I did it.
After the Refresh, you can now switch back to VS2010, select Debug, Attach to Process, and select the W3WP process.
Hope this helps if you are seeing lockups with the Plugin Registration Tool.

Update a Closed / Completed Task

Sometimes there may be an instance where you need to update some fields on a task activity through the SDK, but there is an initial problem.  If you just try to run UpdateObject on the record, it will tell you that you can’t update a task that is closed.

What you have to do is temporarily re-open the task, make the change, then close it again.  This will reflect in your audit log, and any plugin’s on the SetState message will fire, so use accordingly.

In my Method, I am clearing a custom field called InternalQueueId that is a lookup to another entity.

int RecordCount = 1;
int TaskClosedState, TaskClosedStatus;

List<SPS.Task> Tasks = (from t in xrmConnection.TaskSet
                            where t.StatusCode == 5
                                && t.custom_internalqueueid != null
                            orderby t.ActivityId 
                            select t).Take(MaxRecordsToProcess).ToList();
if (Tasks.Count > 0)
    foreach (var t in Tasks)
        TaskClosedState = t.StateCode.Value;
        TaskClosedStatus = t.StatusCode.Value;

        RecordCount += 1;

        // Reopen the task    
        SetStateRequest ssr = new SetStateRequest();
        ssr.EntityMoniker = t.ToEntityReference();
        ssr.State = new OptionSetValue(0);
        ssr.Status = new OptionSetValue(2);
        SetStateResponse resp1 = (SetStateResponse)xrmConnection.Execute(ssr);

        // Update the field and set it back to null
        if (t.custom_internalqueueid != null)
            SPS.Task tUpdate = (Task)xrmConnection.Retrieve(Task.EntityLogicalName, t.Id, new ColumnSet(“activityid”, “custom_internalqueueid”));
            tUpdate.custom_internalqueueid = null;
            UpdateRequest ur = new UpdateRequest()
                    Target = tUpdate,


        // Re-Close the task
        SetStateRequest Closed = new SetStateRequest();
        Closed.EntityMoniker = new EntityReference(t.LogicalName, t.Id);
        Closed.State = new OptionSetValue(TaskClosedState);
        Closed.Status = new OptionSetValue(TaskClosedStatus);
        SetStateResponse resp2 = (SetStateResponse)xrmConnection.Execute(Closed);



    RecordCount -= 1;

Kudos to David Jennaway @ for pointing me in the right direction to solve this.

LINQ Restrictions with CRM 2011 xRM Provider

Apparently there are different rules with the LINQ provider in the CRM 2011 SDK from the CRM 4.0 LINQ provider, and I ran into one today.

I have a process were I am deleting old email activities that meet a specific criteria in the subject line.  I had a LINQ query in CRM 4.0 console app that worked just fine:

var Emails = (
 from e1 in xrmConnection.EmailSet
 join i in xrmConnection.IncidentSet on e1.RegardingObjectId.Id equals i.IncidentId
 where e1.CreatedOn.Value <= dt
 && e1.Subject.ToString().StartsWith(“XYZ:”, true, null) 
 where i.IncidentStageCode.Value == 200999 && i.Custom_ResolvedOn.Value <= dt
 select e1).Take(MaxRecordsToProcess).ToList();

When I ran this same LINQ query in CRM 2011, it didn’t work and threw this error:

Invalid ‘where’ condition. An entity member is invoking an invalid property or method.

After a search, I found this forum post that explained the error and after trial and error I found my specific problem.  The key point is this forum post is this limitation statement:
A limitation of the CRM LINQ provider is that:

    1.The left hand side of a predicate (where clause) MUST be an entity attribute 
    2.The right hand side of a predicate MUST be a literal value or variable 

At first, I didn’t see it because I was putting them in the right order…the problem was the the string check didn’t actually compare it to ‘true’.

var Emails = (
 from e1 in xrmConnection.EmailSet
 join i in xrmConnection.IncidentSet on e1.RegardingObjectId.Id equals i.IncidentId
 where e1.CreatedOn.Value <= dt
 && e1.Subject.ToString().StartsWith(“XYZ:” , true, null) == true
 where i.IncidentStageCode.Value == 200999 && i.Custom_ResolvedOn.Value <= dt
 select e1).Take(MaxRecordsToProcess).ToList();

Adding that ‘== true’ to the string comparison solved it.   


CRM 2011 Switching Forms

One of the custom entities we have in our CRM deployment is used to track System information.  As a result, we have to store LOTS of different data points about each customers installation (Usernames, ip addresses, etc).

Since we have multiple business units, all using the same Dynamics CRM deployment, we have different needs for each unit, but all stored in the same System Entity.  In CRM 4.0 we solved this by storing the data for individual systems on tabs, then show/hide tabs when the form loads.  This worked fine until we ran into the limitation of 8 tabs per form. Ugh.

In CRM 2011 we can now have multiple forms for the same entity, so I wanted to take advantage of this and have the Form Load even determine which form to load for the appropriate system type.

First, I created a new custom entity for System Type, then added a field on that entity for the name of the form to load.  Now when the System form loads, it queries the system type for the form name to use.

The heart of this routine is the call to:
The trick is getting the GUIDs for all the forms.  For that, I built an array and then loop through it.

Hopefully you will find this useful.

function setCorrectSystemForm() {
    var sAlertMessage = ”;

    var arrForms = new Array();
    var iFormCounter = 0;
    var sFormId = ”;
    var oCurrentFormItem = Xrm.Page.ui.formSelector.getCurrentItem();
    var sCurrentForm = oCurrentFormItem.getLabel();
    var sCurrentFormId = oCurrentFormItem.getId();
    var sSystemMainFormId = ”;

    // Load all the forms into an array
        function (item, index) {
            var itemLabel = item.getLabel();
            var itemId = item.getId();

            arrForms[iFormCounter] = new Object();
            arrForms[iFormCounter].name = item.getLabel();
            arrForms[iFormCounter].id = item.getId();
            sAlertMessage += ”  u2219 ” + itemLabel + ” :: ” + itemId + “n”;


    sAlertMessage += “nn iFormCounter = ” + iFormCounter.toString();

    // Query for the form name required for this system
    var sFormType = getSystemTypeFormName();
    var sFormTypeId = ”;

    // Match that name with an ID from our Array
    for (var i = 0; i <= iFormCounter; i++) {
        if (arrForms[i].name == sFormType) {
            sAlertMessage += ‘n This System uses Form :: ‘ + arrForms[i].name + ‘ n id :: ‘ + arrForms[i].id.toString();
            sFormTypeId = arrForms[i].id;

    // Get the default Main form ID in case we haven’t assigned a System Type for this record.
    for (var i = 0; i <= iFormCounter; i++) {
        if (arrForms[i].name == ‘System-Main’) {
            sAlertMessage += ‘nn System-Main Form id :: ‘ + arrForms[i].id.toString();
            sSystemMainFormId = arrForms[i].id;

    sAlertMessage += ‘n ‘;
    sAlertMessage += ‘n sFormType :: ‘ + sFormType;
    sAlertMessage += ‘n sFormTypeId :: ‘ + sFormTypeId;
    sAlertMessage += ‘n ‘;
    sAlertMessage += ‘n sCurrentForm :: ‘ + sCurrentForm;
    sAlertMessage += ‘n sCurrentFormId :: ‘ + sCurrentFormId;

    // Compare the form type required to the current form and navigate as needed.
    if (sFormTypeId != ” && sFormTypeId != sCurrentFormId) {

        // Comment this out to get full debug information
        sAlertMessage = ”;
        sAlertMessage += ‘n Incorrect Form for this System ‘Type’.’;
        sAlertMessage += ‘n Loading Form ‘ + sFormType + ‘ …’;

        // Navigate to the correct form
    } else {
        if (sFormTypeId == ” && sCurrentFormId != sSystemMainFormId) {
            sAlertMessage = ”;
            sAlertMessage += ‘n System ‘Type’ Not Selected!n’
            sAlertMessage += ‘n Select a ‘System Type’ to load correct form for this system…’;
            sAlertMessage += ‘n Defaulting to System-Main form.’;

            // Navigate to the default form
    } // end else if no system type selected