Here’s a quick and easy way to update a plugin assembly in CRM to give much quicker turn around when developing. Note: this will only work if the plugin is deployed to the database.

Plugin assemblies work just the same as all other entities in CRM, which means you can make API calls to retrieve, create or update them. While there is a bit of effort involved in creating new assembly records in CRM and all the associated plugins, steps, images etc. If you want all that to remain the same and to just simply update the deployed code, all you need to do is the following:

var pluginAssembly = new Entity("pluginassembly")
{
  Id = new Guid(pluginAssemblyId),
  Attributes =
  {
    {"content", Convert.ToBase64String(File.ReadAllBytes(assemblyPath))}
  }
};

Where pluginAssemblyId is the id of the assembly you want to update, assemblyPath is the path to the assembly file on disk that you want to deploy and crmService is an authenticated OrganizationServiceProxy (see: my previous post to see how to initialise one)

If you don’t know the id of the assembly, you can look it up via the name first:

var pluginAssemblies = crmService.RetrieveMultiple(new QueryExpression("pluginassembly")
{
  Criteria = new FilterExpression
  {
    Conditions = {new ConditionExpression("name", ConditionOperator.Equal, name)}
  }
});
var pluginAssemblyId = pluginAssemblies.Entities[0].Id;

Assuming the plugin name is the same as the assembly file name, you could also just pull this from the path:

var name = Path.GetFileNameWithoutExtension(assemblyPath);

  •   Posted in: 
  • CRM

This is an updated list – to extend the original list I made in the post here – of the Javascript bookmarks I have in my browsers, to make my life a bit easier as a power user in CRM. While the latest updates have made navigation a bit easier (especially with the addition of an advanced find button on all screens), I still find many of these links easier and quicker to use.

I have left the bookmarks unformatted because I am a bit lazy, but also so they can just be copied into a new bookmark url box without the new lines messing things up. This does mean that they don’t display so well here, so be warned.

GodMode: I picked this one (including the name) up somewhere along the way (sorry, I can’t find the original link to credit them with it), but tweaked it slightly. This essentially unlocks forms for you. It shows all hidden fields, unlocks all locked fields, clears all notifications and expands all tabs and sections. Use with caution as it can potentially circumvent client side controls and allow you to do things that users shouldn’t normally be able. However, anything important is actually being validated server side as well? Right?

javascript:%20try{var%20form=$("iframe").filter(function(){return%20$(this).css("visibility")=="visible"})[0].contentWindow;var%20attrs=form.Xrm.Page.data.entity.attributes.get();for(var%20i%20in%20attrs){attrs[i].setRequiredLevel("none")}var%20contrs=form.Xrm.Page.ui.controls.get();for(var%20i%20in%20contrs){try{contrs[i].setVisible(true);contrs[i].setDisabled(false);contrs[i].clearNotification()}catch(e){}}var%20tabs=form.Xrm.Page.ui.tabs.get();for(var%20i%20in%20tabs){tabs[i].setVisible(true);tabs[i].setDisplayState("expanded");var%20sects=tabs[i].sections.get();for(var%20i%20in%20sects){sects[i].setVisible(true)}}}catch(e){}

ShowSchemaNames:This does what it says on the tin: replaces all the field labels on the form with the schema names. This is useful as a developer when you need to know the name of the field to use in code and saves time instead of opening up the form or customisations.

javascript:function%20getFrame()%20{var%20$iframe%20=%20$('#crmContentPanel%20iframe:not([style*="visibility:%20hidden"])');if%20($iframe.length%20>%200%20&&%20$iframe[0].contentWindow.Xrm.Page.ui)%20{return%20$iframe[0].contentWindow;}else%20{return%20null;}}var%20frame%20=%20getFrame();if%20(frame%20==%20null)%20{alert('Please%20make%20sure%20you%20are%20on%20an%20entity%20form%20and%20try%20again.');}else%20{frame.Xrm.Page.ui.controls.forEach(function(a){a.setLabel(a.getName())});}

GetUrl:Pops up a dialog box with the URL of the current record in it. This gives you a quick way to grab a link to send to someone or open in a new window.

javascript:%20try{var%20iframe%20=%20$("iframe").filter(function%20()%20{%20return%20($(this).css('visibility')%20==%20'visible')%20})[0];var%20url%20=%20iframe.contentWindow.Xrm.Page.context.getClientUrl()%20+%20"/main.aspx?pagetype=entityrecord&etn="%20+%20iframe.contentWindow.Xrm.Page.data.entity.getEntityName()%20+%20"&id="%20+%20iframe.contentWindow.Xrm.Page.data.entity.getId().slice(1,%20-1);if%20(window.prompt("URL:",%20url))%20{%20}}catch(e){}

OpenProperties:Opens the properties page that existed in CRM 2011, but isn’t accessible anymore. Gives you an easy way to see created/modified by/on etc.

javascript:%20try{var%20frame%20=%20$("iframe").filter(function%20()%20{%20return%20($(this).css('visibility')%20==%20'visible')%20});%20var%20id%20=%20frame[0].contentWindow.Xrm.Page.data.entity.getId();%20var%20etc%20=%20frame[0].contentWindow.Xrm.Page.context.getQueryStringParameters().etc;%20frame[0].contentWindow.Mscrm.RibbonActions.openFormProperties(id,%20etc);}catch(e){}

OpenById:Know the schema name and Id of a record that you want to view? Enter those two bits of info in the dialogs that pop up and away you go.

javascript:%20try{var%20iframe%20=%20$("iframe").filter(function%20()%20{%20return%20($(this).css('visibility')%20==%20'visible')%20})[0];var%20entity%20=%20window.prompt("Entity:");var%20id%20=%20window.prompt("Id:");var%20url%20=%20iframe.contentWindow.Xrm.Page.context.getClientUrl()%20+%20"/main.aspx?pagetype=entityrecord&etn="%20+%20entity%20+%20"&id="%20+%20id;window.location%20=%20url;}catch(e){}

GoTo… (the following navigate you to the specified section within the CRM organization you are currently looking at.

Accounts

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Solution/home_solution.aspx?etc=1&sitemappath=SFA|Customers|nav_accts";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);%20void%20(0)}catch(e){}

Contacts

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Solution/home_solution.aspx?etc=2&sitemappath=SFA|Customers|nav_conts";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);}catch(e){}

Opportunities

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Solution/home_solution.aspx?etc=3&sitemappath=SFA|SFA|nav_oppts";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);%20void%20(0)}catch(e){}

Processes

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Solution/home_solution.aspx?etc=4703&sitemappath=Settings|ProcessCenter|nav_workflow";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);%20void%20(0)}catch(e){}

Administration

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Admin/admin.aspx?sitemappath=Settings|System_Setting|nav_administration";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);%20void%20(0)}catch(e){}

SystemJobs

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Solution/home_solution.aspx?etc=4700&sitemappath=Settings|System_Setting|nav_systemjobs";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);%20void%20(0)}catch(e){}

Customizations

javascript:%20try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/systemcustomization/systemcustomization.aspx?pagemode=iframe&sitemappath=Settings%7cCustomizations%7cnav_syscust";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);}catch(e){}

Users(2013 – where Users is under the Administration section in CRM)

javascript:try{var%20o%20=%20new%20Object();%20o.uri%20=%20"/tools/Admin/admin.aspx?sitemappath=Settings|System_Setting|nav_administration&pagemode=iframe&pid=07&web=true";%20window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);}catch(e){}

Users (2015 – where Users is under the Security section in CRM)

javascript:try{var%20o%20=%20new%20Object();o.uri%20=%20"/tools/AdminSecurity/adminsecurity_area.aspx?sitemappath=Settings|System_Setting|nav_security&pagemode=iframe&pid=06&web=true";window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);}catch(e){}

This post follows on from my post last year about registering Service Endpoints in CRM to send messages to an Azure Service Bus.

If you make use of this functionality and were not aware of the pending certificate expiry for CRM you may have had the unpleasant experience of the messages being sent to the service bus queue (or topic etc) failing in the last week or so (as of 7 March 2015). Basically, for security enhancements the existing certificate expired and a new one was issued to authenticate against the Azure service.

All the information you need is here: http://support.microsoft.com/en-us/kb/2836034

To summarise (and in case that link no longer works): If I was organised and got this post out early, the recommendation would be to login to the access control page for your service bus namespace (https://<servicenamespace>-sb.accesscontrol.windows.net/v2/mgmt/web) and under Service Settings –> Service Identities add the new certificate for your region (this can be downloaded from your CRM instance under Settings –> Customizations –> Developer Resources or from the links in the article link above). By having the two certificates installed side by side, you would have been able to have continuous service as they transitioned over and could then remove the old certificate at your own time. Now that it is past the expiry date, if you do not have the new certificate installed you should get this installed ASAP and can just replace the existing one. Once the new certificate is installed (give or take a few minutes for the change to propagate), you should be all good to go again.

So there we go. As with a lot of certificate expiry related issues, there is little to no notification that they are about to expire, so is something that as system administrators we need to be aware of and manage accordingly. We now have a few years to get ready for the new certificate here to expire and need changing again.

If you need to create a long running application to interact with the Microsoft CRM web services – for example, something to perform data migration or integration tasks – you need to be aware that, like all good things, web service connections do not last forever.

Note: the following uses example c# code and the CRM SDK libraries to connect to CRM Online.

First up, we need an instance of OrganizationServiceProxy. This can be created like so:

var uri = new Uri(string.Format("https://{0}.crm.dynamics.com/XRMServices/2011/Organization.svc", orgName));
var clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = username;
clientCredentials.UserName.Password = password;
var deviceCredentials = DeviceIdManager.LoadOrRegisterDevice(); //from SDK: SampleCode\CS\HelperCode\DeviceIdManager.cs 
var organizationServiceProxy = new OrganizationServiceProxy(uri, null, clientCredentials, deviceCredentials);

Now, if you check the IsAuthenticated property on this, you will see that it is false. It is not until you actually use the service to do something that it actually gets authenticated. This lazy authenticating can be useful and saves some time when initialising the OrganizationServiceProxy object, as in the above sample. However, if you made a mistake with the credentials you won't actually know at this point, since it isn't until the authentication actually occurs that the provided credentials are checked. This could be an issue if you don't use the service straight away and don't want to wait until it is needed for you (or the end user of your application) to learn that the provided credentials are incorrect.

More importantly, it also means that when the first request is made there is an overhead to it, because it first has to authenticate and only then can it process the request. If you are creating an application that is waiting for user input or another service to call it, it may be better to take the hit straight up so you can then return responses as quickly as possible to the end user.

Thankfully, this is easily resolved: explicitly authenticate the service after creating it:

organizationServiceProxy.Authenticate();

So now we can get an authenticated connection but, getting back to my initial point, this will not stay so indefinitely. An authenticated OrganizationServiceProxy (against CRM Online at least), has a lifetime of 8 hours, and after this point any attempt to use it to communicate with CRM will result in security exceptions. This is easy enough to work around. Simply add a check before using it to check if the expiry time is coming up and if so call authenticate, which will take a little while, and then carry on with what you were doing.

Rather than trying to add this check before every request to the OrganizationServiceProxy, a better way to do this is to create a subclass of OrganizationServiceProxy and override ValidateAuthentication. This gets called before any other request gets processed, which allows you to write this check in one place and forget about. In this method we, simple add a check to see if the security token is about to expire and if so re-authenticate the service. Like so:

using System;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;

namespace Demo
{
    public class CrmService : OrganizationServiceProxy
    {
        public CrmService(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)
            : base(uri, homeRealmUri, clientCredentials, deviceCredentials)
        {
            Authenticate();
        }

        protected override void ValidateAuthentication()
        {
            EnsureAuthentication();
            base.ValidateAuthentication();
        }

        private void EnsureAuthentication()
        {
            if ((SecurityTokenResponse != null) &&
                (DateTime.UtcNow.Add(TimeSpan.FromMinutes(30)) >= SecurityTokenResponse.Response.Lifetime.Expires))
            {
                Authenticate();
            }
        }
    }
}

In the above example, I also added Authenticate() in the constructor so when you create a new instance of this it comes pre authenticated and you are good to go and use this exactly as you would the standard OrganizationServiceProxy.

I do not particularly like workflows in CRM. Custom workflows in particular. While I concede there are cases where workflows in CRM can work and that certain custom workflows are useful to add additional capabilities to something a power user can control, from my (albeit rather limited) experience, they are often used (or abused?) outside these situations. Especially where a plug-in would be much better suited.

Unfortunately, I have ended up with a project full of them. With over a hundred different processes and 22 custom workflow assemblies referenced by more than 50 them (some referencing multiple), the system is not my perspective of ideal. Regardless, it has fallen to me to upgrade this CRM4 code base and start to get the system in shape for a future move to CRM2013. 

In preparation for this upgrade I was testing the approach to upgrade the workflows and referenced libraries from .NET 3.5, 3 or earlier and replacing references to CRM4 libraries (i.e. Microsoft.Crm.Sdk) with CRM2011 libraries (i.e. Microsoft.Xrm.Sdk etc) and everything that comes with that (replacing CRM4 types: CrmBoolean, CrmNumber, Lookup, DynamicEntity etc). My initial finding was that an in place upgrade of the code would break a deployed workflow. When you deployed the new assembly it seemed to be fine, however new instances of the workflow will fail. If you try deactivate the workflow and edit it you see this:

5

All the steps that reference the custom workflow show an error message and you can't open them to edit or delete them. Other than the error icon, it doesn't provide much information as to what is wrong. To have a look at what was going on, I exported the workflows in a solution and had a look at the XAML. Turns out the workflow itself has references to the input field types and being originally CRM4 based, these are the old CRM types, for example CrmNumber. It seems that this doesn't reconcile when CRM sees the new code that we deployed so it gives up. 

The first fix that came to mind here was to update the XAML to fix these references. This is a bit of a pain, but only really another set of find and replaces. However, it turns out there is a much simpler fix within CRM. All you need to do is open up the workflow (deactivate it if it is active) and then open the properties for the custom activities input (the first Set Properties button in the screen shot above). This will show the inputs for the custom workflow, which should all look the same as before. You don't actually need to change anything here (unless you want to of course), so just save and close out. Again, it looks like nothing has changed and the errors are still there, but hit save and close again. Now just open it up again and all of a sudden the errors are gone.

6

How easy is that! Simply saving the input parameters must trigger CRM to check and update all the parameter types for the workflow, which means the output parameters now match what is expected and the workflow can happily be activated and run. You can confirm this by exporting the workflow again and looking at the XAML.

Awesome, so it seemed like my workflow headaches were going away. That is, until I realised that unlike CRM2011 workflow assemblies, CRM4 did not require the assembly to be signed… and if you sign an assembly it changes the strong name, which means it will not let you provide it as an update for the deployed code, so the above fix was not going to be enough for everything that I was facing... However, how I went about fixing that is a story for another day.