In many development scenarios there is a requirement to perform JScript validations on entity form before the execution of special events by clicking on the entity form buttons i.e. Activate, Deactivate, Lead Qualify, Resolve Case, Cancel Case etc. You can use the step by step guidelines below to overcome this scenario. You may also reffer to the table at bottom of this guide for a list of record saved event model values.
[Instructions]
1. Create a new JScript web resource or you can use existing JScript web resource, copy the following Jscript code in the web resource. Make sure to replace <Value> in code line wod_SaveEventVal = <Value>; with the event mode value as per required. For record saved event model values you can refer to the table at the bottom of the guide.
[Jscript: Code]
// Use the following function on Form Save Event,
// CRM will pass the execution context in function paramter 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();
}
}
}
2. Open Entity Form (Settings->Customization->Customize the System->Entities-> <Entity> ->Forms->Main)
3. Click on Form Properties button, add Jscript web resource library if not already added. In Event Handlers section select OnSave in event field, click on Add button enter FrmOnSave value in function* field and make sure to check Enabled and Pass execution context as first parameter checkboxes.
4. Save Form and Publish entity customizations.
Special Notes Information
1. Event modes having Notes 1 means that system invoke the Save Form event after the execution of the event, so any validations written in the FrmOnSave Jscript method will be executed after the execution of event.
2. Event modes having Notes 2 means that system the Save Event Mode values are duplicated with other Save Event Mode values.
[Table: Entity Record Saved Event Mode Values]
The following table describes the values returned for different ways entity records saved by the user. The save event will be called only for the action">2. Event modes having Notes 2 means that system the Save Event Mode values are duplicated with other Save Event Mode values.
getSaveMode method in the SDK are supported. Others may work, but they may not work in a future version or update rollup.
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) |
16 |
|
Campaign Response |
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 |
|
|
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 |
Fulfill 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 |
|
35 | |||
Product |
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
Close Quote |
25 |
|
User |
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 |
You may need to stop the page from saving if you want the user to fill in some fields they have not yet filled in. You can do this
by adding the line below, which stops the page from saving and leaves the case unresolved.
prmContext.getEventArgs().preventDefault();
You also might want to alert the user with Javascript
alert("You must enter Call Analysis information");