The only thing you'll have to do is: Add this as a webresource to the entities Form that needs javascript. and add the function "OnCrmPageLoad" to the "Form OnLoad" tirgger point!
/* Script Entry Point */Hope you like this script! It's one of the "life saving" scripts for CRM 2011
function OnCrmPageLoad() {
var FormTypes =
{
Undefined: 0,
Create: 1,
Update: 2,
ReadOnly: 3,
Disabled: 4,
QuickCreate: 5,
BulkEdit: 6
}
runAlways();
switch (crmForm.FormType) {
case FormTypes.Create: OnNewFormLoad(); break;
case FormTypes.Update: OnUpdateFormLoad(); break;
case FormTypes.ReadOnly: OnReadOnlyFormLoad(); break;
case FormTypes.Disabled: OnDisabledFormLoad(); break;
case FormTypes.QuickCreate: OnQuickCreateFormLoad(); break;
case FormTypes.BulkEdit: OnBulkEditFormLoad(); break;
case FormTypes.Undefined: alert("Error"); break;
}
}
/* Implement each Form Type you wish to address */
function runAlways() {
onchange(); //Loads all fields that should have onchange functions on them
}
function OnNewFormLoad() {}
function OnUpdateFormLoad() {}
function OnReadOnlyFormLoad() { }
function OnDisabledFormLoad() { }
function OnQuickCreateFormLoad() { }
function OnBulkEditFormLoad() { }
/* --------------- Below is all the Private Functions ---------------------*/
function onchange(){
Xrm.Page.data.entity.attributes.get("prefix_fieldname").addOnChange(examplefunction);
}
function examplefunction(){
alert("Hello World");
}
(it's also avaiable for MS CRM 4.0)
- Happy Scripting!