I had a scenario where the customer wanted the helpdesk user to fill in some call analysis fields when a case was resolved.
Initially I made a new status called Completed, I created some new fields for the users to fill in regarding customer satisfaction, if they resolved the case within the time period and some other fields.
When the user changed the status to completed, some JavaScript made those fields required so the user had to fill them.
This worked fine unless the user press the Resolve Case button and this just closed the case without them having to fill in call analysis fields.
I initially looked into changing the case resolution form. The case resolution form pops up when you press the case resolved button and you have to fill in a few fields, the perfect place for some call analysis. Perfect except you can’t modify it, Microsoft don’t let you modify this Activity. I have no idea why but there you go.
I briefly thought about adding some rules to enable the case resolution button only when you clicked on the status completed.
I then saw some Javascript which did the job. It’s quite clever and I learnt some thing new in CRM.
The solution to my problem was some javascript which is triggered on the OnSave event on the Case form, it checks what type of save has happened and if it was triggered from pressing the Case Resolution it validated the form.
The answer although was shown on many forums originated from the blog post below. The blog post has a link to the javascript file you can download so I would definitely go there to get it. Also this is a great site for CRM developers with lots of other great blog posts like how to trigger a workflow using javascript
The original Javascript and example is taken from this blog post but has now been created as a wiki page blog post below, you need to look at the original article because it explains the whole solution ands walks you through it which I am not going to do.
http://social.technet.microsoft.com/wiki/contents/articles/4122.dynamics-crm-2011-dynamics-crm-2011-perform-jscript-validations-on-entity-form-before-execution-of-special-events.aspx
// Use the following function on Form Save Event,
// CRM will pass the execution context in function parameter prmContext
function FrmOnSave(prmContext) {
// Local variable to store value indicating how the save event was initiated by the user.
var wod_SaveMode, wod_SaveEventVal;
// Change the Save Event Value as per required Save Event
wod_SaveEventVal = <Value>;
if (prmContext != null && prmContext.getEventArgs() != null) {
wod_SaveMode = prmContext.getEventArgs().getSaveMode();
// 1 will pass on Recalculate button click
if (wod_SaveMode == wod_SaveEventVal) {
// Write your validation code here
alert("Write your validation code here");
// Use the code line below only if validation is failed then abort function save event
prmContext.getEventArgs().preventDefault();
}
}
}
You can download the code from the blog link to a skydrive, click here for that
The code above is a neat solution to the problem. In the OnSave event it gets the code to pass variables, this then passes the context. Using the context you can then get the save mode prmContext.getEventArgs().getSaveMode() this gives you a number. If the number is 5 then you know the save has been triggered by pressing the resolve case button.
This was interesting because I didn’t know that save events had different numbers depending on where they were triggered. The blog post has a list of all the save events
Entity
|
Event Mode
|
Value
|
Activities
|
Save as Completed
|
58
|
Activities
|
Close Activity Note 2
|
5
|
Activities
|
To Opportunity Note 2
|
5
|
Activities
|
To Case Note 2
|
5
|
Activities
|
To Lead Note 2
|
5
|
All
|
Save Note 2
|
1
|
All
|
Save and Close
|
2
|
All
|
Deactivate
|
5
|
All
|
Reactivate
|
6
|
Article
|
Submit
|
10
|
Article
|
Approve
|
12
|
Article
|
Reject
|
11
|
Article
|
Unpublish
|
13
|
Campaign Activity
|
Close Campaign Activity
|
5
|
Campaign Activity
|
Distribute Campaign Activity
|
4
|
Campaign Response
|
Convert Campaign Response (Create new lead or Create new record for a customer)
|
54
|
Campaign Response
|
Convert Campaign Response (Convert Existing Lead -> Qualify)
|
16
|
Campaign Response
|
Convert Campaign Response (Convert Existing Lead-> Disqualify)
|
15
|
Campaign Response
|
Close Response
|
5
|
Case
|
Resolve Case
|
5
|
Case
|
Cancel Case
|
40
|
Case
|
Reactivate Case
|
6
|
Contract
|
Invoice Contract
|
38
|
Contract
|
Copy Contract
|
39
|
Contract
|
Recalculate Note 2
|
1
|
Contract
|
Hold Contract
|
31
|
Contract
|
Renew Contract
|
34
|
Contract
|
Cancel Contract
|
33
|
E-mail
|
Send
|
7
|
Goal
|
Recalculate
|
66
|
Goal
|
Close Goal
|
5
|
Invoice
|
Invoice Paid
|
57
|
Invoice
|
Cancel Invoice
|
27
|
Invoice
|
Recalculate
|
1
|
Invoice
|
Get Products
|
44
|
Invoice
|
Lock Pricing
|
52
|
Lead
|
Qualify
|
16
|
Lead
|
Disqualify
|
15
|
Opportunity
|
Close as Won Note 2
|
5
|
Opportunity
|
Close as Lost Note 2
|
5
|
Opportunity
|
Recalculate Opportunity Note 2
|
1
|
Order
|
Create Invoice
|
19
|
Order
|
Fullfill Order
|
56
|
Order
|
Cancel Order
|
26
|
Order
|
Recalculate Note 2
|
1
|
Order
|
Get Product
|
43
|
Order
|
Lock Pricing
|
50
|
Product
|
Convert to Kit
|
35
|
Product
|
Convert to Product
|
36
|
Queue
|
Approve E-mail Note 1
|
4
|
Queue
|
Reject E-mail Note 1
|
4
|
Quote
|
Recalculate Note 2
|
1
|
Quote
|
Get Products
|
28
|
Quote
|
Activate Quote
|
29
|
Quote
|
Create Order
|
17
|
Quote
|
Revise
|
24
|
Quote
|
Close Quote
|
25
|
User
|
Approve E-mail Note 1 & Note 2
|
4
|
User
|
Reject E-mail Note 1 & Note 2
|
4
|
User
|
Change Business Unit Note 1
|
4
|
User or Team Owned Entities
|
Assign
|
47
|
Although I was capturing the save event, when I changed some fields to be required it didn’t seem to stop the page from saving, so I had to add some Javascript which stopped the Case form from saving and popped up a javascript message warning the user to fill in some Call analysis fields. I added some validation which checks to see if certain fields are null, if they are then I stopped the form from saving.
prmContext.getEventArgs().preventDefault();
alert(“You must enter Call Analysis information”);
There are probably other ways to do this but it shows you the power of CRM 2011 that you have quite a few options
Like this:
Like Loading...