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:
- Business Rule error message
- Real-time Workflow status message
- 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.]
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.
How to achieve this:
To do this create a solution by navigating to Settings -> Solutions ->
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.
- Add the Web Resource to the applicable form
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.
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.
- 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.
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.
- 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.
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
- Add the Action(s) to the Rule
- Add a description to the Rule
- 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.
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=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Hello CRM WorldDetail:
<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts”>
<d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema” i:type=”d4p1:string”>0</d2p1:value>
<d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema” i:type=”d4p1:string”>-2146233088</d2p1:value>
<Message>Hello CRM World</Message>
<InnerFault i:nil=”true” />
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.
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.