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 actions that required form save.

Note: Only those values documented for the getSaveMode method in the SDK are supported. Others may work, but they may not work in a future version or update rollup.
EntityEvent ModeValue
ActivitiesSave as Completed58
ActivitiesClose Activity Note 25
ActivitiesTo Opportunity Note 25
ActivitiesTo Case Note 25
ActivitiesTo Lead Note 25
AllSave Note 21
AllSave and Close2
AllDeactivate5
AllReactivate6
ArticleSubmit10
ArticleApprove12
ArticleReject11
ArticleUnpublish13
Campaign ActivityClose Campaign Activity5
Campaign ActivityDistribute Campaign Activity4
Campaign ResponseConvert Campaign Response (Create new lead or Create new record for a customer)54
Campaign ResponseConvert Campaign Response (Convert Existing Lead -> Qualify)16
Campaign ResponseConvert Campaign Response (Convert Existing Lead-> Disqualify)15
Campaign ResponseClose Response5
CaseResolve Case5
CaseCancel Case40
CaseReactivate Case6
ContractInvoice Contract38
ContractCopy Contract39
ContractRecalculate Note 21
ContractHold Contract31
ContractRenew Contract34
ContractCancel Contract33
E-mailSend7
GoalRecalculate66
GoalClose Goal5
InvoiceInvoice Paid57
InvoiceCancel Invoice27
InvoiceRecalculate1
InvoiceGet Products44
InvoiceLock Pricing52
LeadQualify16
LeadDisqualify15
OpportunityClose as Won Note 25
OpportunityClose as Lost Note 25
OpportunityRecalculate Opportunity Note 21
OrderCreate Invoice19
OrderFulfill Order56
OrderCancel Order26
OrderRecalculate Note 21
OrderGet Product43
OrderLock Pricing50
ProductConvert to Kit35
ProductConvert to Product36
QueueApprove E-mail Note 14
QueueReject E-mail Note 14
QuoteRecalculate Note 21
QuoteGet Products28
QuoteActivate Quote29
QuoteCreate Order17
QuoteRevise24
QuoteClose Quote25
UserApprove E-mail Note 1 & Note 24
UserReject E-mail Note 1 & Note 24
UserChange Business Unit Note 14
User or Team Owned EntitiesAssign47

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");