Listen to Field Value Change Events
After registering the FieldValueChange listener for a Task or
Appointment record, handle the OnFieldValueChange event to access details
of the changed fields.
The event payload is available in event.data. Each entry includes the
field name, previous value, and updated value. Here's the format:
[
{
"fieldName": "Task.Subject",
"newValue": "test updated",
"oldValue": "test old"
}
]
| Property | Description |
|---|---|
fieldName |
The identifier of the field that changed. |
oldValue |
The field value before the update. |
newValue |
The field value after the update. |
The following example registers child-record events when the Task or Appointment page opens. When a field value changes, it displays a notification that shows the previous and new values.
define([
'vb/action/actionChain',
'vb/action/actions',
'vb/action/actionUtils',
], (
ActionChain,
Actions,
ActionUtils
) => {
'use strict';
class recordLevelEventListener extends ActionChain {
async run(context, { event }) {
const { $variables, $modules } = context;
switch (event.eventName) {
case 'OnChildRecordOpen': {
const callGetRecordByContext =
await $modules.uiEventsFramework.getRecordByContext(
$variables.uefContext,
{
objectId: event.data.objectId,
objectType: event.data.objectType
}
);
$modules.uiEventsFramework.registerEventsForRecordLevelEvent(
[
'FieldValueChange',
'OnBeforeSave',
'OnAfterSave'
],
callGetRecordByContext.response
);
break;
}
case 'OnFieldValueChange':
if (event.data.objectType === 'Task') {
await Actions.fireNotificationEvent(context, {
summary: 'Field Value Change Event',
message: `${event.data[0].oldValue} to ${event.data[0].newValue}`,
displayMode: 'transient',
type: 'info'
});
}
break;
}
}
}
return recordLevelEventListener;
});
Note: Add the object-type validation before listening record
events. This ensures that the listener is for the intended child object. For
example, use
event.data.objectType === 'Task' for Task records, or
event.data.objectType === 'Appointment' for Appointment
records.