CRM 2011 SDK Dependency Starter now on Nuget

Each time I want to create a quick project in Visual Studio to connect to CRM 2011 I head to the SDK and pull in Microsoft.Xrm.Sdk then the source code for the helper classes and finally resolve all the missing framework dependencies IdentityModel, DirectoryServices etc.  The latter being made considerably easier with Resharper.

I’ve been meaning to package up this process that I’ve now repeated far too many times and throw it up on Nuget.  I finally managed to find the huge 10 minute commitment it eventually took to get this done tonight.

Available on the gallery or to install the package in Visual Studio just open up the Package Manager console and type:

install-package CRMSDKDependencyStarter

or for those of us averse to typing you can shorten this with:

install-p [tab] crm [tab] 

| Tagged | Leave a comment

Taking Team Foundation Service for a quick spin

Having just watched Brian Keller’s talk at //Build online I decided to give the new Team Foundation Service offering a spin. It’s free for teams of up to five users and whilst in preview also free for larger teams. No confirmed pricing plans yet so let’s hope MS don’t go silly if they really want to complete with the likes of GitHub and AppHarbor.

Setup is an absolute breeze having just created an account with my Live ID I was able to create a Team Project and start creating tasks in seconds. Make sure you pick your org name carefully as it cannot be changed at a later date. It also forms part of your URL so company name will be the obvious choice over a specific project name.

Hooking into Visual Studio 2012 is equally easy using the Team Explorer dialog to add a new server you just enter your URL http://xyz.visualstudio.com and you’ll be prompted for Live ID and you’re up and running. I just tried creating a task, pushing it to Outlook (2013) and following the link to view online and all went well. Having been through the pain of setting up an on-premise TFS environment including the SharePoint, SQL Reporting and Build Controllers this is a real step forward for smaller teams and I’ll definitely be digging in a lot more.

In an upcoming post I’ll be taking a closer look at the Azure Continuous Deployment Build Definition and comparing this with the new Continuous Deployment offering for GitHub and CodePlex integration introduced to Azure Websites recently.

If you want to try out any of the new Azure features head over to the Azure Website and sign up for the 10 free Azure Websites offering. Alternatively, if you’re a Microsoft Partner you can sign up for Cloud Essentials for your Azure access and whilst you’re there why not get on board with CRM 2011 Online and Office 365 partner access.

| Leave a comment

Windows 8 – Import pictures directly to a custom SkyDrive folder

If you want to import pictures from a camera or any other USB device straight to a custom SkyDrive folder you can’t do this using the Windows 8 Photo Application. By default it will import all photos to your picture library which won’t be linked to your SkyDrive folder. Whilst you can then upload the imported pictures to SkyDrive manually, this will duplicate the content, it’s far too time consuming and it will also incur the extra download from the SkyDrive servers to sync back with your local SkyDrive folder! There must be a better way.

I’ve fixed this by setting up my pictures library to point straight to the pictures folder within my local SkyDrive folder (which is stored on a second hard disk rather than my SSD where space is always at a premium). That way you’re importing from USB straight to SkyDrive all through the new Windows 8 Photo Application.

  1. Open Windows Explorer (Win + E)
  2. Move all of your pictures from Libraries\Pictures to the folder of your choice within your SkyDrive folder. For most people this will be the default Pictures folder you are provided with SkyDrive.
  3. Right click on Libraries\Pictures and select Properties

  4. Select the path to the current pictures folder most likely C:\Users\username_000. I don’t like the way Windows 8 creates these folder names when using Windows Live for your login.

  5. Click Remove
  6. Click Add
  7. Navigate to the pictures folder within your SkyDrive folder you just moved all your pictures to
  8. Click Include Folder

  9. Click OK.

  10. Click OK.

You now have the Windows 8 Photo Application importing directly to your SkyDrive.

You can also hide the Picture Library from the photo app as this is now just duplicating your SkyDrive folder. Open the charms menu (Win + C) inside the Photo App. Select Settings, Options and uncheck Picture Library. Alternatively you could setup a new “Local” picture library as I have done for importing/storing images you don’t want synced to the cloud.

| Leave a comment

Error when saving URL addressed record in CRM 2011 (Rollup 5)

If you’re on Rollup 6 or higher you can ignore this post.

I came across a problem today when loading a record using the URL addressable form feature as documented over on the Microsoft site here. The record would load fine but when I tried saved the record the page wouldn’t refresh correctly. I would end up with a disabled ribbon and no other page content! The save operation was however succeeding.

I traced this down to an exception being thrown from within the platform JavaScript code. It was making the assumption that the querystring value extraqs was available and calling string.startsWith()which was throwing the null exception.

If you take a look at the URL for any entity loaded via a hyperlink in CRM they all contain this parameter which is typically used to pass attribute values to a form so those values can be pre-populated on load. The value of this parameter must be URL encoded.

Here’s a contact loaded from the default Homepage grid:

http://server/org/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257b0F837B6D-249A-E111-902A-000C2945F65C%257d%26rskey%3d667293691&pagetype=entityrecord

Here’s the sample URL provided for loading an account on the MSDN article linked above:

http://myorg.crm.dynamics.com/main.aspx?etn=account&pagetype=entityrecord&id=%7B91330924-802A-4B0D-A900-34FD9D790829%7D

Switching out the values in blue for environment specific values you’ll see that the record will load correctly. However, if you then make a change and click save the page will hang as show below.


 

Reformatting the sample URL as follows (bolded) will fix the issue when saving the record.

http://myorg.crm.dynamics.com/main.aspx?etn=account&pagetype=entityrecord&id=%7B91330924-802A-4B0D-A900-34FD9D790829%7D&extraqs=anyvalueyoulikeorempty


 

| Leave a comment

Custom Web Pages with CRM 2011 Look and Feel using knockout.js

In this post (it’s been a while!) I’m looking at building a custom html page (ISV hosted or otherwise) that looks as close as possible to the CRM lookup dialog. This will allow us to provide our users with a seamless experience when moving from OOB functionality to custom web pages as was needed on a recent project.

For those that would prefer to skip the how and why and just get the code it’s available on github. Simply plug your data into lookupForm.js along with optional actions for the buttons and away you go. How you choose to get the data into the viewModel is entirely up to you.

This is what we’re trying to reproduce, but outside CRM.

Unfortunately there aren’t any stylesheet or html resources available in the SDK to help us achieve this. There are a set of articles that discuss UX guidelines which are worth a read but none of this information is backed up by reusable templates.

What I needed was a stripped down version of the CRM lookup into which I could add my own code. I found a project created by Darren Lui on Codeplex that is essentially a screen scrape of the HTML and dependent stylesheets for the common forms. It’s a great start but it was missing a number of features I wanted.

Required Features

Reusable

The pages in the template project are a copy of the actual html generated by CRM and therefore it’s a bit tricky to work out exactly where you need to inject your own content and markup into this. CRM 2011 relies heavily on tables for layout so any html purists out there may want to look away now.

Data Separation

I didn’t want to start doing string concatenation to build my html from the data. I wanted to be able to provide the dialog with my own data without having to touch the html and let it build out the page for me. Ideally this should be achieved without the dependency on a server-side framework (ASP.NET). To achieve this I used knockout.js, the MVVM JavaScript framework written by the incredibly smart Steven Sanderson. It allows you to produce a view model in JavaScript and bind this to your html through declarative bindings using the html 5 data-* attributes (don’t worry they’re fully backward compatible to IE6).

Lightweight

The stylesheets used in CRM are quite large and take dependencies on several server-side *.htc files (global.css is 245k incl. all the CSS sprites).

Strip out the html we don’t need from Darren’s template

This was a just a case of stepping through the code bit by bit removing sections and checking the effect of their absence. Not too difficult just quite time consuming. There are many nested tables used in CRM along with custom attributes and as I’ve already mentioned a lot of them exist to provide the rich user experience that I’m not trying to replicate here. Including the knockout bindings and some superfluous commented html the final page is approx. 172 lines rather than the original 492. The size isn’t the issue but the less unnecessary html we have in there in the first place the easier this is going to be for reuse and maintenance by other developers.

Add the declarative bindings (Yes, it’s a screenshot!)

The new container-less bindings available in knockout were used for generating the rows of data dynamically. The much pared down html for generating the data rows is shown below.

Create our View Model in a separate JavaScript file

I created this so that each area of the page that requires data or behaviour is configured on the view model. The code will hopefully be self-explanatory but essentially the column headings are dictated by the headings property, the data rows are in the entities property and the actions bound to the click of each button are bound in the actions object. At the time of writing, the disabling or hiding of buttons isn’t implemented but this will be easy to do using knockout and may well have appeared in the code by the time you read this.

Sort out the StyleSheets

The dialog uses styles from the following stylesheets:

_common/styles/fonts.css

_common/styles/global.css

_common/styles/theme.css

_common/styles/dialogs.css

_common/styles/select.css

_forms/controls/form.css

_forms/controls/controls.css

_controls/lookup/lookupdialogs.css

_grid/appgrid.css

These have all been parsed and the minimum styles required for the dialog have been exported to a single file called lookupForm.css. To reduce the number of dependent files further I’ve also base 64 encoded the button background images used so they are in-lined in the CSS. I’ve also removed all references to the CRM *.htc files.

The end result

Next Steps

  • Bundle this up as a CRM 2011 Solution.
  • Configurable or dynamic column widths based on the data in the column.
  • Due to the removal of all the htc resources the horizontal scrolling of the column headers doesn’t work. I need to look at the best way to re-implement this feature.

Summary

I’m not going to spend much more time on this as its application is pretty specific. In using it you’d need to consider the affect if CRM styles changes. It’s only been tested in IE which is fine at the moment but when the 2012 Q2 rollout drops with support for Chrome, Firefox and mobile you’ll need to consider the effort involved in updating this solution to work in those browsers. Having said this hopefully it will prove useful to others.

Addendum

As I published this I’ve also added the ability to show or hide the checkbox and define an image for each row.

| 1 Comment

.NET Web Development – Now and Next

I recently received an email from a friend and ex-colleague asking about the state of play with respect to web development. Like many of us he’s seen how you can quickly get lost down the rabbit hole with technologies such as JavaScript and all the OS frameworks, CSS, Mobile, HTML5 and ASP.NET MVC. Where are they all going and what’s important right now and in the future. It’s a difficult one and I can only really provide opinion.

Below is my reply which is essentially a cut and paste so it may lose context in some places, but hopefully others will get some use from it.

JavaScript

I believe JavaScript is going to gain hugely in popularity over the next 2 years to be a language way beyond just DOM manipulation.  At the moment the majority of developers, especially us .NET developers tend to use it as if it’s the same as C#.  The only similarity though is the C like syntax.  JavaScript is prototypal, dynamic, functional and object oriented (what a mouthful!).  Essentially what that means is if you’re writing JavaScript in the same way as you write C#, you’re doing it wrong.  There are lots of good resources out there but I’d highly recommend reading anything by Elijah Manor especially this http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/.  Also take a look at his presentations from MIX 2010 and 2011 on JQuery.  He’s on the JQuery team and knows his onions but explains stuff in a way us mortals can understand.  I tweeted (see side bar) a link to a JavaScript patterns guidance repository on GitHub. Go look that up, it’s good stuff.

Do we care about any of the above for DOM manipulation; probably not.  But when you get into using frameworks such as knockout.js for writing web based data-bound MVVM applications you soon realise there’s a bit more to JavaScript than document.getElementById.  Single Page Applications (http://en.wikipedia.org/wiki/Single-page_application) ranging from Gmail through to what will eventually be JavaScript and possibly HTML5 Windows 8 solutions will require a reasonable knowledge of this stuff.

 

HTML5

You need to get past all the noise around things like geolocation and the audio and video tags.  HTML5 is about a rethink of what HTML should be.  No more daft doc types etc.  As an example, take a look at the data-* attribute feature as this is heavily used in things like unobtrusive validation in MVC.  If you’re developing a site today how does HTML5 fit into that picture, what’s the browser support?  Most people think we’re not ready for it yet but in actual fact the spec is smart in terms of backward compatibility.  For example, the data-* attribute will simply be ignored by older browsers.  The JavaScript framework Modernizer will allow you to style new HTML 5 tags in older browsers simply by injecting these elements into the DOM during document load.  Cracking read on HTML5 here http://diveintohtml5.info/index.html

 

AJAX

Get an understanding of how to use it from JQuery ( $.ajax, $.getJSON etc. )  The Microsoft Ajax libraries are dead and no longer supported.  This will be more useful going forward as people start writing web applications with frameworks like knockout.  You’ll be presenting an entire API to the client browser predominantly accessed via ajax with JSON being the data format of choice.  Taking it to the furthest level your API will be RESTful, embracing HTTP rather than abstracting it as WebForms has for the past 10 years.  Microsoft is pushing several stacks for this in terms of OData and the WCF Web API.  A lot of people however are dismissing these in favour of using straight ASP.NET MVC and presenting the API through Controllers that only ever return JsonResult.  It’s like MVC without the V!  No idea where we’ll end up eventually with this one.

 

JSON

See above but essentially it’s nothing more than a data format that’s nice and lightweight over the wire in comparison to SOAP and also plays nicely in terms of being de-serialised into JavaScript objects on the client.

 

CSS

You may have already noticed but as soon as you get into using JQuery you realise you need a good handle on CSS selectors so let’s do that one first.  You’ll have no doubt in the past been down the road of just randomly editing the CSS, refreshing the browser and hoping the CSS gods are looking down upon you and everything now looks as expected.  Unfortunately not a fat lot’s changed in this area but we’re not alone in this camp so there are two OS frameworks called SASS and LESS (http://coding.smashingmagazine.com/2011/09/09/an-introduction-to-less-and-comparison-to-sass/) which aim to alleviate some of the pain experienced with CSS.  Do you need to know these; probably not but again it doesn’t do any harm to know they’re there to help.

 

CSS3

Apart from the ubiquitous border-radius!  Media Queries are the big one here which you’ll hear all about in the same sentence as “Responsive Web Design”.  It’s all about adapting the styles used on a web page based on the viewport (device-width) amongst other attributes.  The most common usage scenarios are therefore styling for desktop or mobile.  MVC 4 is rolling some of this stuff in but also allowing you to easily create media query based or device specific views.  Phil Haack did a decent talk on this at Build.  Search http://channel9.msdn.com .

 

JQuery

Know it, learn it, and love it.  You’ll be doing nothing without it.  As mentioned up there get your head around the $.ajax API and understand CSS selectors.  The best thing I’ve found about JQuery is it’s so ubiquitous now that all you have to do is think about what you want to achieve, type it into Google and append jQuery to the end.  Cut, paste and job done.  Next level on from that is writing a plugin and then if you’re so inclined JQueryUI which is all about widgets and presentation and finally JQueryMobile which is a mixture of JQueryUI and HTML5 for the mobile devices.  I knocked up a half decent iPad version of my LearnAndGame site (see below) literally in about 10 minutes. I’m over simplifying JQuery here as it’s so much more but that’ll do for now.

 

ASP.NET MVC

Get the HTML5 Boilerplate template off the extensions gallery within VS.  This shows you some great guidance on website best practice.  It’s a bit over the top as a starting point for a site in my opinion but a good reference for learning.  Moving on nicely from that also go get the NuGet gallery source from GitHub as this is also a great reference site for MVC development.

 

WHAT NEXT

Take a deep breath and go grab a scotch! After that I’d recommend taking a look at knockout.js http://knockoutjs.com as mentioned above.  It’s a fantastic framework and will really help you get to grips with writing JavaScript using best practice.  If you’re anything like me you’ll get terribly distracted when reading samples of code and not understanding what the JavaScript is doing.  You’ll head off to find out more, spend a few hours in http://jsfiddle.net getting hopelessly lost and eventually find your way back to where you started.  This can be insanely frustrating but at the same time immense fun.  Personally, it’s why I love being a developer.

If you’re so inclined feel free to get your Git** and GitHub mojo on and fork my LearnAndGame repository here https://github.com/Daxaar .  At the moment it’s nothing more than a playground for my learning JavaScript but I’ve got some high aspirations for that as a learning platform for kids.  At the moment it’s taking a serious dip in priorities.

** Quite simply the most bonkers and yet wonderful Distributed Version Control System (DVCS) known to man.  It makes working in TFS version control feel like seriously hard work.

 

Have fun
Daz

| Leave a comment

Changing the scope of the AssignedTo field in TFS 2010 Work Items

This post is related to changes for Team Foundation Server 2010 but a similar process can also be followed for TFS 2008.

For so long I’ve been meaning to sort out the list of names that appear in the AssignedTo dropdown list when creating work items. This evening I’ve been making some changes to our work item Status workflow following some positive feedback from the QA team and so finally got around to fixing this.


By default it will show all of the Active Directory users that have access to the project. That unfortunately includes all of the system administrators and service accounts, TFS related or otherwise that will be imposed upon you through group policy.

What we need is the ability to restrict this list to only those people pertinent to the project. At the simplest level that would be those people within the TFS Project Contributors group. In a future post I’ll look at filtering this list further based on additional attributes of the work item. For example, subsequent to setting the status to Triaged, you may only want to assign to members of the development team. For now let’s keep it simple.

I’m going to assume you’re comfortable with the TFS Power Tools (available as an Extension in VS 2010) as it’s through the Process Editor available in this extension that we’ll be making our change.

You have a couple of choices here. You can either edit the Work Item Template against a Process Template or as I’m doing directly for now, against the WIT for an existing project.


Select the Work Item Type from the appropriate project in the dialog that pops up and you’ll be presented with the Work Item Editor screen thus:


Double click Assigned To and select the Rules tab on the dialog


You won’t have ALLOWEDVALUES in your list. It’s the setup of this rule that filters the list of displayed names.

Click New and enter the name of the TFS group you want to restrict the list to.


In our case I’m restricting to the Contributors group for the current project. Note the highlighted [project] should be as is and not substituted for your own project name.

Close down all the dialogs and save the template (either import if you exported or just save). If you did this against an existing project go in and create a Work Item of the modified type and hopefully you’ll see a much cleaner list. If your AD is setup correctly it’ll pull in Full Name otherwise you’ll get just the login name.

I hope this is of some use and please don’t be afraid to get stuck into modifying your process templates and work items. Whilst it’s always a good idea to start with the OOB template never be afraid to modify it to suit your own needs. Especially if in our case it helps in getting some real usage out of TFS

Summary

You can restrict the names that appear in the AssignedTo list by adding an ALLOWEDVALUES rule to the attribute within the Work Item Template.

| 2 Comments