Hello CRM World

Hello CRM World,

This is my first blog post so I thought I would say hello the best way I know how…in Dynamics CRM of course.

There are actually 4 different methods for giving feedback to the user:

  1. JavaScript Alert
  2. Business Rule error message
  3. Real-time Workflow status message
  4. Plugin [I’m not a developer so I won’t be talking about this. The end result is the same type of message that can be delivered through the Real-time Workflow method. The Real-time Workflow does give one advantage which I will speak about.]

1. JavaScript Alert

This is most widely known way of alerting the user or providing feedback and I would say most popular method of doing so especially in CRM 2011 and previous versions. This may change as the Business Rules are getting more and more powerful with more features announced in CRM 2015 & here.

Hello CRM World JavaScript


How to achieve this:

  • Create a JavaScript Web Resource

To do this create a solution by navigating to Settings -> Solutions ->

Create a Solution

Give your solution a name and select the default publisher. I’ll speak more about the benefits of using a custom publisher to make your customisations in a later post.

Once you have created your solution navigate to Web Resources and create a new Web Resource with the type Script (JScript). My suggestion is to create a JavaScript web resource per entity and another generic Global Library that will store common functions that you will use over and over again. CRM will ask for a name now, this will change from company to company and developer to developer. If you’re unsure what naming conventions you have at your company ask your developers but if you name it something like EntityName.js or EntityName_Library.js this will be sufficient for other people working on the same site.

  • Add the Web Resource to the applicable form

In your newly created solution navigate to Entities -> Entity Name you want add JavaScript to (Contact in this example). Open up Forms and open up the Form that is the default form that CRM users are going to be directed to.Using multiple forms is useful for Support teams where the Support engineers will see a different screen as opposed to their manager.

Navigating the Solution

After opening up your Form navigate to Form Properties and add a new Form Library (the web resource we have just created).

Click OK then Save and Publish.

  • Create the JavaScript function with the alert method.

The next step is to actually write your JavaScript function and add it into your Form Library. My suggestion if you don’t have Visual Studio installed is to use a program called Notepad++. There are numerous programs that perform the same functionality but Notepad++ is just a personal preference and I enjoy using it.

Here is a screenshot of the code I’m using with the alert method. The best way of learning to code sometimes is to write it out yourself.

Hello World Function

  • Add the function as an event for the respective field – Ensure it is enabled.

So now we have some code we want to run but we need to specify where and when it’s going to run.

There are 3 possibilities for when:

  • On Load of the form
  • On Save of the form
  • On Change of a field

There are 2 possibilities for where (this is where you are going to be adding the event handlers – functions):

  • The form for functions you want to run on load and on save of the form
  • The field that is being updated to produce a certain action (event)

For this change I am loading it into the field’s events. To do this double click on the respective field and navigate to the Events tab. Add a new Event Handler and use the same function name that you used earlier.

Field Properties

Event Handler

Once you have completed all these you will see your alert.


2. Business Rule Error Message

As more and more consultants and CRM specialists discover the benefits of using Business Rules and with customers moving to CRM 2013 or to the soon to be released CRM 2015 then there will definitely be more of an uptake of the use of Business Rules.

You can use Business Rules to show an error message to the user. Unfortunately Business Rules are still a little bit basic in CRM 2013 so there are still a lot of scenarios where I would like this to happen that would need custom JavaScript or a code Plugin. Some of these scenarios would be String handling validations on:

  • ID Numbers – Correct length
  • National Insurance Numbers – Correct character order / correct length

But back to the topic, I am going to demonstrate how to create a Business Rule and what the error message looks like to the user.

Business Rule Error Message

The Business Rule error will show a Red icon with a White cross and if you hover the field then you will see the error message that you configure in the Business Rule.

How to achieve this:

  • Create the Business Rule(s)

A Business Rule can be created from the Customise Form area or from the solution under the relevant entity. If you want to Activate/Deactivate multiple Business Rules at once then you will need to do so from the area in the solution.

  • Add the Condition(s) to the Rule

Business Rule Condition

  • Add the Action(s) to the Rule

Business Rule Action

  • Add a description to the Rule

Business Rule Description

  • Activate the Rule

Make sure to activate the Rule and publish all customisations.

If you are curious to see a list of all Business Rules in the system you can follow these steps.

3. Real-time Workflow Status Message

The third method I am going to be discussing is the use of Real-time Workflows. I found out about this really fantastic feature from this link. For anyone working with Dynamics CRM, Gareth Tucker’s blog is a must read as he has a wealth of knowledge and experience.

Real Time Workflow Error Message

For anyone accustomed to code plugins you will notice this is the same type of error message that appears. However, Microsoft have added quite a nice breakdown of the Workflow steps if you click on Download Log File.

This is what is produced

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Hello CRM WorldDetail:
<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts”&gt;
  <ErrorDetails xmlns:d2p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic”&gt;
      <d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema&#8221; i:type=”d4p1:string”>0</d2p1:value>
      <d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema&#8221; i:type=”d4p1:string”>-2146233088</d2p1:value>
  <Message>Hello CRM World</Message>
  <InnerFault i:nil=”true” />

[Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin]
[803a1d35-fe68-e411-80df-0050568f00d8: ]
Starting sync workflow ‘Contact – Stop save of Contact with Last Name World’, Id: 7a3a1d35-fe68-e411-80df-0050568f00d8
Entering ConditionStep1_step: If Last Name Contains data and Last Name equals World
Entering StopWorkflowStep3_step: Stop workflow with canceled
Sync workflow ‘Contact – Stop save of Contact with Last Name World’ terminated with error ‘Hello CRM World’


As you can see the error description is quite informative and gives the consultant a quick glance of what happened, why the error message was generated and what workflow generated the error. The advantage of this over your code plugins is that it is far more difficult to debug your plugin to see why the error message is generated and at what step the error message was generated. With If…Else logic added to CRM 2013 SP1 for Workflows I can see more consultants and developers using Workflows as opposed to code plugins to do basic validations.

Please note the useful step descriptions shown above in the log file are the descriptions I placed in each Workflow step. This is equivalent of putting comments in JavaScript code. It is essential to do it and makes supporting the system going forward much easier.

Real-time Workflow Details

I hope you enjoyed my first blog post and found it in informative. Please post comments and let me know if there are any other ways that I didn’t think about.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s