How to dynamically register event handlers in Model driven app forms
Normally we can use Form configuration to attach On Load, On Save, On Change events as given below.
But for some business needs if you want to declare the event handlers in code dynamically then use below method. Remember Registering event handlers using code is possible for all handlers except OnLoad, which must be registered using configuration. OnLoad handler can then be used to register other handlers in code.
function FormOnLoad(executionContext)
{
var formContext = executionContext.getFormContext();
formContext.getAttribute('accountnumber').addOnChange(OnChangeAccountNumber)
}
function OnChangeAccountNumber(executionContext)
{
var formContext = executionContext.getFormContext();
formContext.ui.setFormNotification('Check account number', 'INFO', 'AcctNumber');
}
Hope this helps