When to automatically change fields using Javascript

I had an interesting bug in a CRM 2011 CRM solution.

  • Open a record
  • change no variables and just load the record
  • close the record and then a an alert ‘Your changes have not been saved’ are you sure you want to close the record

The user was opening a record, doing nothing but when they went to shut down the record they were asked if they want save their changes

The user is left thinking, I haven’t changed anything. Do I want to save these changes I didn’t make or throw them away? This decision is tricky because you haven’t a clue what has changed.

Why are fields being changed on the on load

I have seen this type of scenario before and it usually occurs because a developer has tried to sneak a calculated field change, e.g. when a contact form is loaded the CRM developer might calculate the full name of a user by concatenating the users names and then updating the fullname field.

The CRM developer has changed a field and made it dirty and only dirty fields are sent to CRM to be saved.

CRM is a place where only dirty entities and fields are saved! The clean fields are ignored. Who invented this crazy world

if you want to understand about dirty fields and what gets saved then read about the SetSubmitMode in this blog post
CRM 2011/2013 – What does setSubmitMode do? and how does it work?

How to find what field has changed

I had two choices in this scenario, I could either try and find what field is being set by looking at the code or stepping through it.

Unfortunately this was a record with lots of Javascript.

The other choice was to see what CRM attributes have had the SetSubmitMode set to dirty and use the IsDirty Javascript method.

This blog post had the Javascript to do the job

MS CRM 2011 – What is the “IsDirty” Method ?

I didn’t want to create a method in the Javascript to call, so instead I brought up the Javascript debugger by pressing F12. Ran this code in the console

var attributes = frames[0].Xrm.Page.data.entity.attributes.get()
var listoffields = "";
for (var i in attributes)
var attribute = attributes[i];
if (attribute.getIsDirty()){
listoffields = listoffields + attribute.getName() + " , ";

The reason I concatenate the fields is once a value is printed in the console it stopped running, so I wanted the output to be after it gave me a list of all the fields which have changed.

It turned out one field was being set. The field was a concatenation of records linked to the record. The related fields were being shown in an html grid and when the user selected a record in the grid, the record was being updated instantly using an odata update.  As well as the record being updated there was also some javascript to update a field on the record with a comma separated list of selected records.

To calculate or not to calculate

This is a common problem when CRM developers put calculating javascript code into a form onload. The problem with doing this is the user might not save the record and in which case you will have calculated nothing and potentially confused the user by triggering the save alert.

This scenario can put the developer in a tricky situation when you have a record in the situation described below

  • You want to calculate a field for the entity and have this field value saved
  • The record does not need to be saved by the user

This problem occurs because the CRM developer is using Javascript on a form on load, so a field  value is changed/calculated.

A lot of times you can smuggle you calculated field in amongst user changes to a record so the user doesn’t know the CRM developer has sneakily calculated a field.

If this Javascript is on a record which is often viewed but not changed then I would advise CRM developers not to use Javascript in the onload of the form because the Javascript is not effective because it can keep running and not save the record.

The other factor you need to consider is the potential confusion you are adding to the user when a mysterious save alert.

Would it happen in CRM 2013/CRM 2015

I haven’t tried it but I was wondering if this would happen in CRM 2013/CRM 2015 because they have auto saving.

Auto saving could be turned off, so CRM 2013/CRM 2015 could still work in the same way as CRM 2011.

It’s possible you could try and close the form before the auto save has been triggered, I’m not sure if a save is triggered on closing of a form?

Alternative customization choices

The problem raised is the CRM developer is using an ineffective customization because the record is not automatically being saved.   The important question is does this field need to be updated or when does the field need to be updated.

Where and when is the calculated field used e.g how urgent is this field calculation.

If the field value is used in a plugin then a calculation check could be made before the field value is used and this wouldn’t degrade the user experience.

The goal of CRM customizations is to seamlessly work behind the scenes to make the system easier to use/save user time/automate processes.  The customization in this scenario isn’t making the user journey easier but puzzling them.

what are the alternatives?

This field calculation should be triggered on the save of a record.  In this scenario the record itself is not being saved.  In most scenarios I think you could put this code into the OnSave of the record either in Javascript or a plugin.


if the record doesn’t need to be saved then I think in this particular scenario you have a couple of choices.

The related record update could trigger a plugin to update the record.


An OData update which updates the record on change of the related record which is triggered by an html grid but is then triggering a change to a related entity.

How to cope when you are out of your Developer comfort zone

Don’t be afraid to say you don’t know something, you will always know less than there is to know. All you can do is to keep learning every day – Hosk

Experience is doing something new, making mistakes and not repeating those mistakes next time you do it – Hosk


When you get kicked out of your  comfort zone.  calm down, break the problem down, list what you need to do and don’t breakdown. Hosk

I was reading the well-written article about being a new developer

As a new developer

It neatly sums the fears of new developers trying to get started with development with only miniscle knowledge of development, surrounded by people who have been developming for years.

How the Heck am I going to do that?

I tweeted this and got a good response from CRM MVP Jamie Miley (see what happens if you stick at it kids)

how the heck

It got me thinking, there are times and situations when suddenly you get kicked well and truly out of your comfort zone

This could happen in a number of scenarios, some good, some bad and some scenarios life throws up just for the hell of it.

  • Promotion and new responsibilities
  • a new job/role
  • A developers leaves and you are parachuted into the project
  • working with new software/programming language

So how do you cope when you are out of your comfort zone

Step one – DON’T PANIC

Calm down, big breaths, it’s time to think logically.  When you are out of your comfort zone, you initial response is


Similar to going somewhere you have never been before, everything seem unusual and strange and in your mind the geography can seem endless because you don’t have concepts of distance of landmarks.

After you have wandered around a town for some time, it shrinks in size as the unknown area slowly becomes recognisable and manageable.

How do you eat an elephant?

You should see all problems as elephants you need to eat?

Most people see an elephant and think, it’s impossible to eat an elephant but this is because you are letting the problem (eating the elephant) overwealm you.  You need to break it down into eating the elephants ear or eating a bit of the elephants ear.

The answer to how you eat an elephant is, one bite at a time.

Don’t listen to your fears

This is similar to doing development in a computer language  or types of customizations you haven’t done before.  You usually have someone asking you for an estimate of how long something is going to take but how do you know you have never done it before.  You start to panic, you roughly think it would take this long but what if it’s tricky, WHAT IF I CANT GET IT TO WORK EVER!!!!

The devil who was snoozing on your left shoulder, cackles in delight and starts generating worst case scenarios, which no doubt involve you being sacked and shamed, being made to wear a billboard round town saying “I couldn’t code a WCF web service to interact with CRM”.

Don’t visualise all the things which can wrong, instead focus on this being a brilliant opportunity to learn new skills and show how capable you are.

Difficult tasks are solutions you haven’t yet created

Step two –  continue to calm down and engage brain

Calm down.  What you have to do is get the facts clear, work out what you know and then make a plan.

Just like writing code you need to simplify the problem and remove complexity 

  • What do you know about the problem?
  • What needs to be done?
  • How can it be done?
  • Questions/problems about the requirements and the solution

The different zones of uncomfortable

Here are some of the common tasks you might not have done before

  • Designing a solution
  • Creating new functionality/customization you haven’t done before
  • Integrating with 3rd party software
  • writing a WCF webservice
  • Using new software
  • Using a new coding language
  • Estimating a solution
  • setting up/installing software
  • Impossible Deadline

General Advice

Before I go into detail on some of the scenario’s above, I will go over some generic advice for surviving CRM development when you doing something out of your comfort zone.

Don’t panic

The don’t panic advice can be used in most scenarios.  Remember you are a skilled individual who has done similar pieces of development.

  • Keep calm
  • Work out what needs to be done
  • Split up the tasks into small parts
  • evaluate any potential risks
  • Ask advice from your peers and colleagues

Don’t be overwhelmed

At the start of a piece of development there is an initial moment where you think

How the heck am I going to do this, I have never done this before I don’t know how

Go back to the don’t panic advice and remember you have done big pieces of development before and if you haven’t, well there is always a first time.

A big piece of development is just lots of small pieces of development stuck together.

Don’t sit and suffer in silence

If you can’t do something and you have tried breaking it down but still don’t know where to start then it’s time to ask someone to point you in the right direction.

All Developers have been in the same situation as you are in right now at some point.

It’s time to get up from your seat and get some help.  Remember the task here is for the development to get done

If you can’t do it, speak up sooner rather than later

If you really can’t do the development then you need to raise this as soon as possible and someone who can do it can be resourced to do it.

It may be embarrassing at the time but your employer/boss will be grateful you raised it with enough time to get someone else to do it.

You can learn how to do it by seeing how the developer did it, maybe even working with them.

Afterwards you can go away and research the area yourself, so next time you will be able to do it.

Designing a Solution

Designing/architecting a solution can be daunting if you haven’t done it before.   What you need to remember is you could have done most of it, if you were made to but usually the Solutions architect does it.

The first task is to make sure all the requirements have been gathered and then study these carefully to see if you can come up with any questions.  The reason it’s important to make sure you capture all the requirements it’s easier to change a solution design than change a solution design and code.

When gathering requirements for CRM projects, you often do what’s known as Gap fit analysis

Gap fit analysis is where you compare the out of the box functionality in CRM with the requirements, working out what you can do with default CRM and what will be a customization

When designing a CRM solution try and break it down into smaller parts and break down these parts into the development you need to do to create the functionality.

When developing a CRM solution break the requirements down into separate user roles to help you understand how different users will use the system, what functionality each different user role need.

Create entity diagrams and flow diagrams to help you understand the requirement and your proposed solution design.

It’s a good idea to get someone to check your design, they will be able to find obvious problems and make suggestions.

Creating new functionality/customization you haven’t done before

Creating a customization type for the first time could be

  • Plugin
  • Custom workflow
  • Dialog
  • Action
  • Javascript

The first task is to find a working example of the customization, often you will be able to find an example of the customization inside the CRM project you are working on done by another developer.

If you cannot find any examples then you should search the internet or check the CRM SDK for some sample code.  You can also search the Hosk CRM blog which has lots of examples of CRM customization.

Once you see an example it’s easier to understand how it works and modify it for your needs.

Start simple and get the basic example of the customization working and then add your requirements.

Integrating with 3rd party software

This can be very tricky and some 3rd party software can have a complete lack of usable documentation.

One risk with using 3rd party software is finding out the limitations and quirks of the 3rd party software.

Writing a WCF web service

When writing working with CRM you will often need to integrate CRM with other systems and software a customer is using.

Many times you will need to create a WCF web service.

This isn’t any easy task and if you have never done it before you will have to learn quickly.  There are lots of good WCF tutorials on the internet and you will need to find one you can understand.  The other tricky part of writing a WCF tutorial is deploying it.

I have written a little bit about a WCF service and there are some good tutorials at the end

WCF with no service xml or endpoints? What is this magic?

Estimating a solution

Estimating is one of the scariest tasks a CRM developer can be asked to do.  The weight of the financial consequences of your estimate can be a worry.

As always keep calm, break down the development into small tasks and then estimate those tasks.

If their parts of the development you haven’t done before or parts you feel are risky then add some more time to the estimate.

Add all the tasks and estimates into an excel spreadsheet so you can justify your the amount of development time if you need to.

Breaking down the development will give you confidence in your estimate.

Configuring or installing software

There are lots of different pieces of software to install and configure with CRM Email router, Outlook

  • Email router
  • Outlook add in
  • CRM server
  • SQL Server
  • SSRS reporting server

There is some great documentation about installing and setting up CRM software and one of the key parts to installing/configuring is making sure the server meets the prerequisite requirements.

Know what service user accounts you will be using in your install and the privileges these will need, often you will need a domain admin to create the service accounts and this can take a few days with some IT departments.

Another tip is to download any software and prerequisite software you might need because a lot of servers will not have internet access.

Back up everything before you start

In most cases it will be going through and pressing next a lot of times.

Impossible Deadline

Customers will sometimes press the panic button and need some development/CRM project urgently and will insist on impossible project deadline.

I have written here why this isn’t a good idea

Why rushed projects/code doesn’t save time and reduces quality

Raise your objections about the rushed deadline and lower expectations it might not be possible.  Do your best and if you have to work extra hours/overtime make sure you get this time back and bring it up in your yearly review.


How to prepare for these situations

There will come a situation which you will be doing some CRM development for the first time but you can prepare for some of this situations.

Solutions architect

The best way to prepare designing CRM solutions is to design CRM solutions.  I appreciate the advice is clearly in the category of “bleedin obvious”.

The problems you find when designing a solution only occur when you are deep into the design and only when you really look at a design will potential problems become apparant.  In similar way to have theoretical knowledge of writing CRM plugins, custom workflows or a WCF service will help you, until you have created a CRM customization you won’t have experienced all the problems which occur when trying to get code to work.

When writing code, customizations, functionality, software products you haven’t used before you will create a lot of errors which you overcome by reading the documentation and trying different things.

In the blog post-Why .Net developers struggle with CRM development I go through the knowledge you need to get a plugin working.

Designing a CRM solution has a similar learning curve (probably most activities do) and you will only encounter and overcome these problems by experiencing them.  To experience the problems you have to go through the process of designing a CRM solution as if it was real project otherwise you won’t do it properly and not worry about the solution not working.

A good way to practice is to get the requirements for projects your company has done and design a CRM solution for it.  You can then compare your solution with the solution that was implemented.  Once you have your design you can ask a solutions architect or a senior developer to look at your CRM solution and give feedback.  If the person who designed the implemented CRM solution is still at the company you can ask him about the implemented solution.


Estimating a solution

Similar to designing a CRM solution, the best way to practise estimating development is to practise estimating development.

Go through previous CRM developments requirements and practise estimating and then comparing your estimate to the estimate given.  You can ask the CRM developer involved in the original estimate to explain his estimate and ask other CRM developers for advice.

Configuring or installing software

Practice installing/configuring CRM software before you need to do it on a customer project.  You can ask the IT department if there are any virtual machines you can practise installing software on or you can get your own virtual machine and install CRM with a demo license.

Creating new functionality/customization you haven’t done before

Any CRM development you haven’t done before you should get some experience doing yourself with a CRM trial version.

Once you have done it once you will have working version to modify and the experience of getting it working.


One of the hardest parts of CRM development is doing something for the first time and the best way to prepare is to practise.  Practising development, installing software, designing solutions, estimating etc will allow you to go through the process without the pressure of doing the process for a customer.

When delivering a CRM development activity for a customer there is pressure to produce the development activity in good time and to a high standard.  When you practise the development activity on your own these pressures don’t exist and you can concentrate on the activity.


Hosk Top CRM Articles of the week – 27th Feb

Article of the week

Diving into the Product Structure of Microsoft Dynamics CRM 2015 (and meet ET)
A detailed post and video on the new product structure

Best of the Rest

CRM SQL Query go faster trick – SQL Server trace flag 8780

Training & Adoption Kit for Microsoft Dynamics CRM
A good bunch of links for new CRM users.

9 reasons to replace excel spreadsheet with CRM
How CRM can replace a business excel

XRMtoolbox updated
A couple of interesting things. Field Level Security bulk updater has been updated and XRMToolbox has been moved to github

Why the advanced find is a CRM Developers best friend

Why CRM Advanced find is soo useful to CRM developers

Tip #329: Resolve Missing Record Dependencies
resolving missing dependencies

Why your CRM code and customizations should be simple
The benefits of writing simple customizations

You can do system-wide alerts in CRM 2015

Using “Roslyn” to Catch CRM Coding Issues
A detailed and interesting blog post looking at the new features and how to use them with CRM

Custom State Model Transitions in Spring Release for Dynamics CRM 2013
This is a really cool piece of functionality, managing what statuses a record can move to. I still haven’t come close to using it yet.

What are the hidden costs of excluding user adoption in your Microsoft Dynamics CRM implementation plan?
A good article looking at the hidden costs

Unit Testing Plugins using Microsoft Fakes
A great post on testing Microsoft plugins with Microsoft Fakes


CRM SQL Query go faster trick – SQL Server trace flag 8780

A developer was looking at some reports to try and improve performance and they were advised by Microsoft to use a trick which I had never heard off setting SQL Server trace flag 8780

I know what you are thinking

“Hosk, you didn’t even know about turning on SQL Server trace flag 8780, amateur”

Everyday is a school, so prepare yourself for today’s lesson

What difference did turning on the flag

The performance was dramatically improved, changing the report speed from 14 seconds down to 1 second!


I’m interested tell me more

The report was an SQL report and to turn on the flag you simply put the this line at the end of the SQL statement, after the where clause.

option (querytraceon 8780)


select name, accountid, telephone1

from account

where name = ‘hosk’

option (querytraceon 8780)

The good thing to note is you can turn this flag on for individual queries.

What does the flag do

The developer called it the “make it faster” setting on SQL. The query in the report was joining three different tables and one of them was contact.

warning – the description below is my understanding, it could well be wrong but it will give you an idea of what I think is happening, more research by yourself would need to be done if you are thinking of using it.

When SQL queries run on SQL Server the SQL server creates an execution plan. SQL Server calculates the most efficient way to retrieve the data you want. When the query is compiled if the execution plan can’t find a quick it will time out and then go with the best one it had found so far.

There could be other more effective execution plans for your SQL statement and if you gave the execution plan a bit more time it could find them.

When I mention time, I’m talking milliseconds (which is a long time for SQL Server)

In the report we were joining the contact table but using a contact guid but the execution plan was timing out because the execution plan was doing a full table scan of the contact table (2 million rows).

Whilst it was trying to scan the whole contact table it timed out and gave up (who can blame it)

SQL Server trace flag – 8780 to the rescue. This flag gives the sql optimizer more time to find the most effective (e.g. quickest) way to retrieve the data.

You set the flag (which can be set server side or for each individual query) this increases the time limit before the optimizer timeout occurs.

The result in our reports meant the execution plan found a better way to optimize the query and the reports ran a lot of faster.

What are the downsides

Traceflags in SQL Server are undocumented and unsupported by Microsoft (unless they advise you to use it :-)

I view traceflags as developer tools written by developers but not fully tested in all scenarios. This means Microsoft doesn’t know how the queries will react in all scenarios.

The obvious danger by turning off the time limit for optimizing a query I guess is it could keep on optimizing for a long time. The problem is no one really knows what it’s going to do

When to use it

If you have some reports which are taking a long time to run and you have been asked to optimize them, turning on the this flag for individual queries (e.g. reports) could save you a lot of time.

It’s unsupported so I would suggest you only use it when you really need to

Further reading

I couldn’t find a lot of information on this mysterious trace flag but these three articles will help you learn more

Optimizer Timeout or Optimizer memory abort

 Is it possible to give the optimizer more or all the time it needs

SL Server Trace flag – 8780

Why your CRM code and customizations should be simple


“Simplicity is the end result of long, hard work, not the starting point” – Frederick Maitland


“Simplicity is the Ultimate Sophistication” Leonardo da Vinci

In a previous blog post I wrote about complexity in code and customizations and the problems this can cause.

The problems with complex code and complex CRM Customizations

Complex code is hard to understand code because classes and methods do so many different things it’s impossible to understand how it works without stepping through the code to understand exactly what is going on. – Hosk

A quick recap
Here are some of the main culprits of complex code
  • Large methods – Monster methods
  • confusingly named classes, methods and variables
  • methods which do lots of things
  • not consistent
  • tight coupling
  • dependent code
  • poorly structured code
The problems associated with complex code
  • No Reuse
  • Complex Code is hard understand/read
  • Complex Code/customization is difficult to debug, maintain and extend
  • Creates complex bugs
  • Encourages more of the same

Code should be well structured, split up into logical classes and methods and the everything should have meaningful/logical names.  One part of good simple code is to make it readable, which makes it easy to understand when a developer is scanning the code looking for bugs or see where they should extend the code to add new functionality.

Methods should be in small and do one thing, this should ensure it takes out decoupling.

A lot of the work involved in keeping the code and customizations simple is managing the complexity of the CRM solution.

Writing code and customizations which seem simple is very challenging, it takes time spent on design, coding standards and will power.

Keeping the code simple is worth the effect because it’s so much easier to use and work with.  When you see great code it’s a thing of beauty, often surprisingly simple looking and will make you think you could easily write it yourself.

Keep it simple stupid

When you are writing code, keep in mind the KISS principle, below is a great summary from Wikipedia
The KISS principle states that most systems work best if they are kept simple rather than made complicated; therefore simplicity should be a key goal in design and unnecessary complexity should be avoided. The phrase has been associated with aircraft engineer Kelly Johnson (1910–1990).[3] The term “KISS principle” was in popular use by 1970.[4] Variations on the phrase include “keep it short and simple” and “keep it simple and straightforward”.[5][6]
Like most great advice in life and in coding, it can be broken down so it’s easy to understand but challenging to implement.
The KISS principle is described by the code it creates, simple and elegent.  When I  see an example of great code I am often amazed by the beauty and simplicity of it.  Code which adheres to the KISS principle is using small, tidy, precise, does one thing and does it well.

Make your code simple

if you do the above the code will be
  • Simple to test
  • Simple to maintain
  • Simple to debug
  • Simple to extend
The benefits of simple code is it’s simple to

Easy to Understand

If your code simple and the complexity removed then understanding the code is easier.


A good way to test if your code is simple, is to see if you could easily write a unit test for your code.  If you code is well written and the methods and classes are independent and have loose coupling.  Focused code is easier to write unit tests for because the methods do one thing and the tests only have to test the methods do the one thing.

Code which has loose coupling is very modular which means you can use it in other parts of the code or in other projects because the methods are not dependent on other methods in the project.

Making code for reuse sounds easy but I have found it’s unusual, which is why this quote has a ring of truth to it

code reusability in CRM projects is seen as often as bigfoot or the loch ness monster – Hosk
For more Hosk Quotes check out my Hosk Developer quotes page

No Extra Code

Simple code can be made to be extendable but it should not include any extra code which isn’t needed.  Simple code should go through refactoring so not only does it not contain any unneeded/unwanted code but the complexity is managed the quality is high.

Don’t add any extra functionality which might be used in the future.  The code should have been designed to be extendable.


There should be CRM standards document which all developers should have read and stick to.  Code consistency should also be considered when designing code solutions so the code is the same in different projects.

When code is structured differently when written by different developers it can make a project difficult to understand.

Easy to understand

Simple code should be easy to understand because it’s logically structured and consistent.  The code should be readable

What does this mean for a CRM developer

It’s easy to say “make your code simple” but how do we do that.   I would also focus on making your CRM customizations simple, including business rules, workflows

Front end

Looking at CRM from a user’s perspective, CRM should be as easy as possible to use.  CRM forms should be organised so a user can intuitively use the form.

An easy way to understand this is Good CRM design should not make users think

a few key points from the blog post which make CRM simple to use

  • Don’t make them think
  • Users are like sharks – they don’t stop moving and clicking
  • User like back buttons – it helps them to not get stuck
  • Users like searching
  • give them fewer options – filter options
The benefits of a simple user interface/CRM Form design
  • it’s easy to use
  • Users like using it
  • fewer barriers for using the system
  • Gets support on the customer end

Simple CODE

The key to simple code is the classes and methods focus on doing one thing.  As soon as classes and methods start doing more than one thing, they become hard to name, the code becomes coupled.  Code which does more than one thing becomes complex

Independent code

When trying to write simple code you should try to focus on writing independent code.  To write independent code means  classes and methods are focused and do one thing.

Easy to name variables and methods

When you write simple code you will find it’s easy to name classes, methods and variables and if you are struggling to name one of those its usually a side effect the code is trying to do more than one thing.

The great boon of writing simple code is it’s easy to understand because classes, methods and variables do what they say they do. Complex code is hard to understand code because classes and methods do so many different things it’s impossible to understand how it works without stepping through the code to understand exactly what is going on

Small Methods/functions which do one thing

You should write small methods, the reason for writing small methods is it will focus the methods, this makes the code reusable and easily tested.

Small simple methods are easy to understand, maintain, debug, extend.

reduce complexity

  • Classes and methods should do one thing
  • Independent code – the code isn’t coupled
  • Small focused methods

Don’t use lots of different customizations

There are lots of different types of customizations in CRM
  • Javascript
  • Business rules
  • workflow
  • plugins
  • Dialog
  • Console Application
  • Web Services

When I decide what type of customization to use in CRM for a particular problem, I usually go through this process

1.  What customization type can provide the functionality needed
2.  What customization type is best suited to provide the functionality
3.  What customizations already exist in this area and in the project

The process creates a list of possibles, which I whittle down to probables and then I need to match the probable solutions with the existing solutions in the project.

The reason for this is because if you have lots of overlapping customizations it makes maintaining, debugging and extending the CRM solution as a whole a lot more difficult.

I have experienced bugs where a plugin has a changed a value of a field, which then gets overwritten by a workflow.  The reason for this is plugins are usually syncronise and workflows are usually asyncronis.  In the bug I was investigating the workflow was running after the plugin.

I have also seen many questions from users on the CRM forums asking how Javascript and Business rules interacting.  Business rules do not trigger javascript on change events.  This makes understanding the customizations difficult because sometimes the Javascript onchange is triggered and sometimes it’s not.  It also means the CRM developer has to be aware business rules do not trigger Javascript on change events and make sure they create the customizations with this in mind.

To simplify it (which is what this blog post is all about)

Increase in types of customization = increased complexity

Your goal in creating a customization is not only to add the required functionality but good developers will concentrate on creating customizations which are simple because simple customizations are easy to understand, debug, maintain and enhance.


Customizations in a project should be consistent, even if it isn’t the best way of structuring the customization.  An example could be if a project only uses Linq queries and these Linq queries are in separate classes for each entity.  When someone else writes some plugin code they should use the same structure.


The most important part of writing a plugin is it does what it’s meant to do and provide the functionality needed.

Goal of a plugin

1.  To deliver the functionality required
2.  To produce quality code with the fewest bugs in
3.  To produce code which is easily maintained, debugged, extended
4.  To produce code which is easily understand

To create a plugin which has simple code it means you have you should not put it all in one big method directly in the plugin, yet how many times have you seen this in a CRM project?

Split up the code into classes which work logically e.g. entities or business logic/retrieves etc.

create small methods which do one thing.


Creating code which is as simple as possible really is breaking the code down into small independent parts which work together as a whole CRM solution.

Managing complexity is a never-ending task for a CRM developer, the better you do it the easier it is to work with the CRM project and code within it.

The main benefit of breaking the design and code into small simple parts is it’s easier to understand small simple parts and how they fit together.  This becomes more important when CRM developers work on multiple projects or have had worked on another project and come back.  Simple code will be easier and quicker to understand when you have lost the understanding of the business logic associated with the project.

Creating simple code and customizations looks easy (when you see the end product) but is extremely challenging to do.  Complexity of a CRM solution can quickly increase if the CRM developers are not focused on managing complexity and keeping the CRM solution as simple as possible.

Why the advanced find is a CRM Developers best friend

Microsoft caused quite a bit of unrest when they released CRM 2013, suddenly making the Advanced find button difficult to find, if you are interested I wrote about that in this post – Good CRM design should not make users think

In this post I want to write why I love the advanced find functionality in Microsoft Dynamics CRM.

I view the CRM Advanced find as an awesome swiss army knife


To new users and inexperienced CRM developers it looks like a simple tool to search the records in CRM.

To an experienced CRM developer it’s one of the key weapons in the CRM Developers armoury which when used correctly can save you loads of time and make your life a whole lot easier.

It can speed up navigation, help you create queries for your plugins, export and enrich data and even help you fix bugs.  In some cases when being brought onto an existing product, I have used the advanced find to go directly to records of a certain type because I didn’t know where to look in the CRM system.

What is advanced find

Advanced find is a tool which allows you to create queries against the CRM database.  It allows you to select the fields you want to see in the results and filter the query with conditions.

You can then save this advanced find query as a personal view

The Advanced find is a lot more than just a tool to query CRM because in many situations it can

  • Save you time
  • help you understand
  • view field values and related entity field values
  • speed navigation

The reason CRM Advanced find is so useful (and why users and CRM developers were annoyed when Microsoft made it hard to find) is CRM is really one big database full of useful data.  The CRM GUI

  • view the data using a web browser
  • validate the data input
  • organise the data into forms etc
  • Add security
  • organise using the data
  • Development to automate adding/viewing data

The CRM GUI (website) has lots of functionality for validating and displaying the data.  This is really useful but for CRM Developers they often want to navigate the system quickly and are not interested in the GUI and business logic but just want to get to certain records.

The advanced find lets you search all the records in your CRM database and apply a filter condition to allow you to only bring back the records you are interested in.

One important consideration to remember when using the advanced find is it does apply your security profile, so you will only see what records your security profile has privileges to see.

Quickly find the records you need

The beauty of advanced find is it can bypass most the GUI and get to the record you want you want with a couple of clicks.

It can also bring back groups of records you want, which is more difficult to do with the front end GUI

The great thing is you can save the advanced find into a view so you can repeat the process even quicker next time.

When you don’t know the business logic

In some projects a CRM developer can be brought into the project in the bug fixing phase. It can be difficult to fix bugs when you don’t understand the business logic or how the system works.

Using the advanced find can help you easily navigate to the entity records you are interested because with the advanced find you can view all the entities in alphabetical order.

This can help you if the bug exists on a specific record type and you don’t need to understand the business logic, e.g.

  • Javascript form errors
  • Simple plugin triggering on update

FetchXML is a great place to create your query

When I have to create a query in a plugin, I usually start with an advanced find to get the logic correct.

You can then download the FetchXML and you can see which fields you need to use and how the filters should be structured

You can use FetchXML in Javascript

You can use fetchXML’s directly in your javascript. I usually use OData queries and the odata query tool.   One of the limitations of OData is it doesn’t have a distinct attribute, so there is no way to not retrieve duplicate records.

The query I was interested in doing needed to filter out the duplicates so I did it in FetchXML.  When I didn’t filtered out duplicates (the OData query) it was returning 1500 records, which slowed down the form load but when I used FetchXML with distinct set to true, it returned 25 records.

FetchXML directly in plugins

You can run FetxchXML code directly in your CRM plugins instead of query CRM using  Linq or QueryExpression.

I go through the process in the blog post below

 Build Queries with FetchXML instead of QueryExpression

One of the advantages of using FetchXML in a plugin is you can create the query in Advanced find which can sometimes be easier

Create saved views

Saved views can save you lots of time because you are only viewing the records you are interested in and filtering out all the other entities.

Export data

Using the Advanced find to select not only the records you are interested in but also the fields is very useful.

Being able to export these records and send them to someone who doesn’t have access to CRM is a very handy trick to customers.

Exporting the data will also allow you to move the data between CRM organisations and environments (e.g. Dev, Test, Prod)

Enrich Data – e.g. export, change, import

The good old Enrich data functionality, which is has the good, the bad and the ugly all in one.  It’s called Enrich the data but what it really means is you can export some records and when you import them it will automatically know which records to update.

enrich data

The enriching data functionality works by adding the Guid of the records to the export file (and some checksum columns etc) which are read by CRM when you re-import the data.  If it sees the values it knows you are not importing new data by updating/enriching existing data.

Bulk Edit

Once you have a list of the entities you are interested in, it’s easy to bulk edit those records and assign them all the values.

Bulk editing data in this way can add data which bypasses some of the validation in the GUI forms.  The reason for this is business rules and Javascript do not run because they are only triggered on the CRM form.


Hosk Top CRM Articles of the week – 20th Feb

Article of the Week

This article explains how you can prepare for a CRM 2015 upgrade.

CRM 2015 Upgrade: A Few Things You Can Prepare Ahead of Time


Best of the Rest

I wrote a very long blog post on why rushed code and projects doesn’t save time, If you haven’t read it then I think you should
Why rushed projects/code doesn’t save time and reduces



Very good blog post by CRM MVP Jukka about how to use bookmarks to speed up your CRM 2015/2013 navigation

CRM Navigation Hacking with Bookmarks

A great blog post looking the new CRM 2015 hierarchical security model

Exploring the Hierarchical Security model in CRM 2015


How to add users in CRM 2015, could be trickier than you think

CRM 2015 – How to add users


When you write a plugin, you often need to debug it to see what it’s doing. Videos are always good when understanding development.

Good video on debugging plugins in CRM 2015


Understand what it means to put a plugin in the sandbox

Understanding Plugin sandbox mode

A new FetchXML tool

FetchXML Builder for XrmToolbox

Useful, just the kind of thing a customer would ask for

Dynamics PDF – Convert CRM Reports to PDF & Attach to Email


How to Load test using the visual studio ultimate edition (warning costly).

Load Testing Microsoft Dynamics CRM 2013


If you are upgrading to CRM 2015 and you have some customizations to upgrade then use the custom code validation tool to check they are ok
Microsoft Dynamics CRM 2015 Custom Code Validation Tool

If you want to some words of wisdom from the Hosk

HoskWisdom – Hosk Developer Quotes