- 
								
																
																
									Dynamics 365 Entity Form Script Template
									JavaScript
									Dynamics 365 Entity Form Script Template
								 
							 	
						
						
						This script serves as a template for Dynamics 365 entity form customizations, providing structured methods for handling `OnLoad`, `OnSave`, and field `OnChange` events. It ensures a reusable and organized approach to managing form interactions and validations.
"undefined" === typeof CONSOTO && (CONSOTO = {
    __namespace: true
});
CONSOTO.Entity = {
    formContext: null,
    // OnLoad function: called when the form is fully loaded, and components are accessible
    OnLoad: function OnLoad(execContext) {
        CONSOTO.Entity.formContext = execContext.getFormContext();
        try {
            var formtype = CONSOTO.Entity.formContext.ui.getFormType();
			CONSOTO.Entity.RegisterAddOnChange("name", CONSOTO.Entity.CustomFunction);
        }
        catch (err) {
            Xrm.Utility.alertDialog("Something happened !");
        }
    },
    // OnSave method is called when the form is saved, automatically or manually
    OnSave: function OnSave(execContext) {
        // Make operation
    },
    CustomFunction: function() {
        // Triggered when field name changes
    },
    RegisterAddOnChange: function (idValue, method, unRegister) {
        if (typeof method != "function") {
            unRegister = method;
            method = null;
        }
        var attribute = CONSOTO.Entity.formContext.getAttribute(idValue);
        if (attribute) {
            if (typeof unRegister == "undefined") {
                attribute.removeOnChange(method);
                attribute.addOnChange(method);
            }
        }
    }
};