Why .NET developers struggle with CRM Development

Experience is important for a CRM Developers. You have to learn how things don’t work first 🙂 no shortcuts

CRM Developers have to learn the mysterious ways of CRM development, they need to learn the the quirks and the way things work with Microsoft Dynamics CRM development.

Microsoft Dynamics CRM can be illogical but we are all used it to now.

If CRM was an animal I think it would be a cat, it’s unpreditable and sometimes very difficult to persuade it to do as you would like

CRM

This makes experience very important because to learn how things work, you have to go through the process of things not working (often in many different flavours of not working) before it works

There are some shortcuts but often you have to go through the painful process yourself.

LIKE WHAT

 

Plugins

When a CRM developer starts developing a plugin, he will learn the all the steps you need to take and the hoops you need to jump through

I went through some of the common problems in this blog but here is a quick recap

  • setup up CRM Developer toolkit
  • User has to be CRM Admin
  • Isolation mode? if none user has to be a deployment administrator
  • plugin needs to be signed
  • crmRegister file needs to be checked out

These are the simple things you need to do to create and register a plugin, that’s without even thinking about the code and if it works, testing, debugging etc.

CRM tools

There are lots of tools where you have to put the server, the CRM Discovery URL, the OganisationService url.

At first you guess what they are, fail a bunch of times until you knuckle down and find out where those urls are, what they do and why the tool needs them.

Use Microsoft Dynamics CRM services in code

Then one day you find they are hidden in CRM under settings, developer resources!

CRM 2011 – Discovery and organization service are held in settings

WHY .NET/C# struggle developing

Sometimes companies don’t want to pay for CRM developer or have C# resources which they think they will use to do some CRM plugin customization.

This theory seems like a sound idea, the actual C# code in a plugin is usually quite small and not overly complex but for a C# Developer with no CRM experience it’s a total nightmare

C# developers with no Microsoft Dynamics CRM development experience don’t understand how data in the CRM website is structured in SQL Server database

  • How CRM works with customizations
  • The different types of customizations to choose from, without this knowledge how do you pick the correct customization type.
  • How do I create a plugin
  • How do you register a plugin – common plugin errors
  • How do I write a query to retrieve related records in CRM

Whilst the C# developer goes through learning how things don’t work, it takes the developer a lot longer to write the plugin (if they manage it)

The kicker is if they don’t do constant CRM Development, they will forgot all the lessons they learnt from the work above, slide down the snake and have to learn all again next time.

Hands on experience is vital

The reason hand’s on experience is vital for CRM developers is when a CRM developer is creating customizations and code to work, they will have to overcome a lot of situations where the code isn’t compiling, it isn’t working.  During this minor setbacks you the CRM developers will read blogs, the SDK and work out why it doesn’t work.

The CRM developer will end up with a working customization, e.g. plugin but will also have a better understanding of creating CRM customizations and a more in depth knowledge of how the CRM customization works.

You cannot get this knowledge and experience through reading about CRM customizations like plugins, custom workflows etc.

Creating the customization gives you a deeper knowledge of CRM development because reading about CRM development won’t tell you about what doesn’t work.

If you think about knowledge as 3 dimensional object, reading about CRM Development gives you one view of the object.  Getting it working and overcoming the errors during this process gives you a different view of the object.

Experience is earned

When you start creating CRM plugins, worfklows and other customizations you will run into lots of puzzling problems.  Slowly one by one you will overcome the initial problems and find more intricate problems, which usually move towards logical problems and quirks particular to CRM development.

e.g.

The point I am trying to make is CRM Developers learn CRM development by overcoming errors and problems and learning not to make them in the future.

The CRM developer will make less errors whilst creating their CRM customizations (plugins, custom workflows, Javascript, etc), this gives them time to focus on refactoring their code, new functionality, testing, writing better structured code (which is readable).  Their understanding of the underlying CRM structure grows and becomes more in depth.

I view CRM developer progression similar to driving a car.  When you start out driving a car, everything is difficult and you have to think and remind yourself to do these tasks

  • Putting on your seatbelt
  • Seat right positioned correctly
  • Constantly checking all of your mirrors
  • Indicating at the correct time
  • Changing gears and being in the right gear
  • Braking distance
  • Estimate distance
  • Monitoring speed (and not speeding)
  • Understanding what the road signs mean

The driver slowly gets more experienced and begins to do many of the those tasks without thinking, this gives them time to focus on other parts of driving, like not crashing and watching out for idiots on the road.  Driving on the motorway, driving in the rain and snow are all experiences built up over time.  Slowly the driver will become better (hopefully).

The point is you can’t read how to become a better driver, you have to apply the knowledge and experience it yourself.  The same is true about CRM development.

The only way to speed up experience is to do some CRM development outside of work.

Example

Mark McGookin had been working on some CRM development and getting IFrame errors.  Errors messages rarely point to the actual problem as most CRM developer find out.  Error messages are a sign something went wrong and you need to do some detective work to find the root cause.  You can do this by checking your logging, Plugin Trace files, Event Viewer on the CRM server or by debugging the customization.

 

Mark was trying to use Document Management in his code, eventually he found the iFrame error was actually occurring because the SP Root location was null.

crm dev experience

Summary

Experienced CRM developers make less errors because they have learnt to stop making these errors through experience and bug fixing those problems.

Due to the experience and knowledge gained through experience and reading they will make better choices about what customizations work well in certain scenarios

One the key roles experience developers have is advising and peer reviewing less experienced developers.  Finding problems and bugs earlier in the process can save you hours if those same bugs are found when the CRM customization has gone to the customer.

 

12 Ways to become a better CRM Developer

Now and again I get asked how to become a better CRM Developer, so I thought I would create a blog to point people towards and here it is.

1.  Decide you want become a better Developer

Improving and becoming a better CRM Developer is a state of mind/attitude, you have to want to get better, you have to strive to be better every day.

It’s like trying to get someone to read a book you like, you can’t make them read that book no matter how good you say it is, it’s only when the person wants to read it.

 

2.  Make a plan

A plan is like a map, if you don’t use a map it’s very difficult to get to where you want to go.  A plan is the same for careers and learning skills, you need to identify the skills you want to learn and make a plan to learn them

What areas do you need to improve in?

  • Plugins
  • Javascript
  • CRM 2013 new features
  • CRM 2015 new features
  • WCF webservices
  • Dialogs
  • Certifications
  • programming
  • reports (Bids and SSRS)
  • Data import (Scribe, SSRS)

Make a plan to start learning and getting experience with the above areas.

3.  Read Blogs

I believe all CRM developers should have a selection of blogs on CRM.  These links have some great blogs

Top 25 Dynamics CRM Sites – featured on Dynamics 101

Blogs featured on Microsoft dynamics blog list

Twitter is also a great way to find interesting CRM blogs.

CRM blogs provide technical knowledge and examples of new functionality and CRM development usually written by a CRM expert.

4.  Write blog posts about CRM Development

A great way to learn CRM Development is to write blogs and teach others CRM functionality.  This will not only increase your profile and brand in the Microsoft Dynamics CRM community but you will also understand the functionality better by explaining it.

Clearly explaining how functionality and technical ideas will involve you understanding the topic in greater detail and analyising it before expressing those ideas on your blog.

As an added bonus you will easily be able to find your notes on the subject, I often search my blog solutions to problems and quite often find articles/solutions I forgotten I had written.

Writing about CRM Development reinforces the knowledge, increases understanding of what didn’t work and what did work.

5.  Create Customizations – Write Code

You cannot learn CRM development purely by reading, you have to get your hands dirty and do the development yourself.

One reason practical experience is so useful is getting things to work is a major hurdle in development and until you do you can’t be sure you can or how difficult it is.  The process of getting code to work is usually going through many iterations of the code not working and you learning from your mistakes until you get it working.

Understanding how code doesn’t work gives you a great understanding of how CRM code does work.

The experience of getting an example to work will give you confidence and a working example when it comes to using the functionality in a CRM project.

6.  Learn from your colleagues

All CRM developers have individual areas of expertise their colleagues do not have and you can learn new techniques and skills from your colleagues.   CRM Development and coding is a world where there are millions of classes, methods and functions which it’s impossible to know about all of them, good developers will sniff out the really useful ones but often someone will tell you a technique/method you have never heard of which could make your life loads easier.

You can learn from

  • Peer reviews
  • Reading code written by your colleagues
  • Talking about CRM development

7.  Never stop learning

Becoming a great CRM Developer is a journey which never ends.  There is always

  • New functionality to learn
  • Better techniques
  • New tools
  • New technologies
  • Teaching others
  • Learning from your mistakes
  • Learning from your successes
  • Loads of other things I haven’t mentioned or don’t even know about yet

 

8.  Stop to think – analyse what you have done

An important step in CRM Development is making sure you stop and think about the CRM development/customizations you have done.

A good time to think about things you have worked on is during a lunch time walk.  Think about how you could have done things differently, the good and bad points.

Analysing your development can help you identify weaknesses in your code and understand why.

For every bad line of code you avoid writing the increased chance of a good line of code taking its place.

Sometimes getting better is not making as many mistakes as the project before.

9.  Don’t take the easy option

If you want to get better you have to constantly push yourself to be a better CRM developer.  This means getting involved in difficult projects and tricky customizations.

Keep up to date with the new functionality in Microsoft Dynamics CRM and try to work on projects which are delivering the latest releases.

Don’t let your standards drop and don’t check in bad code with a promise to refactor it later.

10.  Create free tools – Give yourself a project

Not only will you create something useful for yourself and others, hopefully more useful than this

Hosk’s CRM 2013 Guid Getter

You will learn skills, overcome many problems, get some great experience and learn new skills.

If you are not sure what tool/solution to create then think if there are any things which could be automated in your company or if there something which could be automated or improved in CRM.

It could be Access Team template import/exporter to solve the problem I discussed in the blog post CRM 2013 – Why are access teams marooned?

11.  Read Books

When I say read books, I don’t mean just read CRM or Developer books but you should read all types of books.  Great ideas can come from all areas of life and reading books are a great way to switch off from CRM and focus on something different, you will get ideas/thoughts which will enable you too look at CRM from a different view point.

Some good developer books, which aren’t really about Development I talk about here

Recommended Reading for Developers

The coding horror list is a great list of books, most of them focus on people and processes rather than writing code, which is logical because you will spend as much time interacting with people as you will writing code

Coding Horror – Recommended Reading list for Developers

If you don’t like reading then I would suggest listening to some audio books during your commute or when you are doing the cleaning.

On a personal note, I love science fiction books and have been working my way through the SF Masterworks list

12.  Have other hobbies

Remember, there is more to life than CRM Development so make sure you are spending time with your family and loves ones and get yourself a hobby or a sport, you have to switch off and get your life in balance.

Finally

CRM development is great fun, don’t forget to enjoy yourself.

 

 

 

 

 

CRM 2013 – using Entity.GetAttributeValue instead of Entity.Contains

I found myself writing this tried and tested code, which I have written many times before

if (entity.Contains("salutation"))
{
     title = ( string)entity.Attributes["salutation"];
}

before you can get a value from the entity attributes you need to check the field is included in the list of parameters. I traditionally use to do this using entity.Contains(“fieldname”), if the field specified exists in the list of parameters it will return true. The reason this works is because CRM doesn’t pass null values in the parameter list, so if its null it won’t exist.

Often in code you will lines and lines of Entity.Contains code, checking the field exists before assigned the value.

Is there a better way

I remember an excellent post featured on CRM MCC Guido on his blog CRM Answers
Entity.GetAttributeValue and ActivityParty

The article was about using Entity.GetAttributeValue and in this blog he linked to an excellent and detailed explanation of how Entity.GetAttributeValue works from CRM MVP Dave Berry

Entity.GetAttributeValue Explained

I had a classic case of reading how to do something in a better way but automatically doing it the way I always did it, except I now had a chance to do it differently and that’s what I did.

 

What is the Entity Class

The Entity class is the base class in CRM development and this class holds some key details about what entity it is

LogicalName – logical name of the record e.g. contact,account, lead
Id – ID of the record

The other important values are the Attributes. The attributes are a collection of attributes, e.g. all the fields in the entity/record.

What is the difference between an entity and a record

Entity

The entity e.g. account, contact, lead.  This is the design of an entity but doesn’t hold any values.  I would liken this to an object and an instance of an object.

Record

A record is an entity but with values, e.g. someone has created a New contact and this creates an instance of an entity (the design) and makes a record with individual values (e.g. name = Hosk, description = marvellous);

It uses object to enable it hold the various different variable types possible, it will mean if you are using late binding you will need to cast the values into the type you are expecting.

 

Trying Entity.GetAttributeValue

I thought I would try it out because it would save me wrapping if statements round things and seemed a better way to do things.

initially I removed the contains if statement and I got a variable doesn’t exist type error, hmm this isn’t meant to happen , I then realised it was a user error

I actually hadn’t typed it in but just removed the if
title = (string)entity.Attributes[ “title”];

I then added the proper method
title = entity.GetAttributeValue(“title”);

 

When developing I usually test my plugin code by making my plugin code take a iOrganisationService instance and an entity and put these in a separate class. This means the plugin can call my class but more importantly it means I can call this class by creating an iOrganisationService and an Entity object and not worry about any of the other plugin stuff. This enables me to call my new code in a console app which creates an IOrganisationService connected to the Dev environment and then do a service.Retrieve(“contact”, guid, columnset);

So I kicked of my console app and this retrieved a contact record and selected the title record and in this case the value was null and the code set the string title variable to null.

 

So I used this to retrieve a OptionSetValue and string and it worked fine.

it’s important to note this will bring null back if there is no value or the value is null.

Also remember for some types it will bring back the default value if something doesn’t exist and this might not be what your code is expecting.  In Dave’s blog he has a handy table

Type Return
Numerical (int, decimal, double) 0
Boolean false
DateTime DateTime.MinValue
Guid Guid.Empty

 

Why isn’t Hosk using Early binding

A question you are asking is why is the Hosk using Entity instead of an early bound class like Contact or Lead.  Great question, I’m glad you asked 🙂

The reason I am using the entity class is because the plugin was going to run on the contact and lead entity and maybe some other entities in the future.  The fields had he same name on the different entities, this enabled me to write the code (using Entity) which would work on both Contact and Lead.

CRM 2013 – Convert Email HTML to Plain Text

I have had this request from a few customers over the years and it’s converting and using the description of an email is trickier than you initially think it will be.  This is a question which often appears on the CRM forum quite regularly as well.

The reason for this is although the email looks like plain text when you see it in CRM, when you get the value of the Email entity description (main body of the email) you will also get all the HTML tags.

The scenario I had when I was doing this was the customer wanted to convert an email into a case and get the values from description.

So to do this I had to strip out the HTML tags and a few other things, which I did using a plugin

if you have to do this here a couple

This blog post is excellent

http://ashwaniashwin.wordpress.com/2014/04/16/convert-html-to-plain-text-for-copying-email-message-in-crm-2011-2013/

C# code

http://aliraza.wordpress.com/2007/07/05/how-to-remove-html-tags-from-string-in-c/

A sample plugin

http://blogs.msdn.com/b/ukcrm/archive/2008/07/10/converting-html-e-mail-to-plain-text.aspx

 

Recently I saw Steve Green had created a CRM Video going through the process and  I thought I would promote the video on the blog because he also has a link to the code here https://dl.dropboxusercontent.com/u/4041841/CRMDemo2014.zip

 

 

I would also recommend anyone who wants to learn CRM development to go through Steve’s other CRM videos, many of them are in CRM 2011 but the code would still work in CRM 2013.