CRM 2011 Javascript Cancelling Onsave Event

*Note make sure you have a parameter defined to receive the Execution Object
Javascript Eg.



function EitherOne(executionObj) {
    var Field1 = Xrm.Page.data.entity.attributes.get("customerid").getValue();
    var Field2 = Xrm.Page.data.entity.attributes.get("vw_name").getValue();


    if (Field1 == null && Field2 == null) {
        alert('Either Customer or Name fields need to be entered with data.');
        // The getEventArgs() method returns an object with methods to manage the Save event.
        // The preventDefault() method cancels the save operation        executionObj.getEventArgs().preventDefault();
        Xrm.Page.ui.controls.get("customerid").setFocus();
    }
    else { onSave(); }
}


End of Script


Where to place the script?
*Note Make sure u check the pass execution context as first parameter.


0 comments: