OnBeforeSave Event
This event is started before the API request to commit the data to the server. You can then do asynchronous operations in this callback or cancel this event. This event can wait for an asynchronous operation to be completed. With this event, the user will get complete control of the save event that happens in VB by either approving or canceling this operation in VB.
Note: OnBeforeSave is an event listenable from RecordContext
The following code sample shows an example in TypeScript for subscribing to OnBeforeSave
event:
const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const tabContext: ITabContext = await frameworkProvider.getTabContext();
const recordContext: IRecordContext = await tabContext.getActiveRecord();
const requestObject: IEventRequest =
frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnBeforeSaveEvent');
recordContext.subscribe(requestObject, (response: IEventResponse) => {
// custom code
return new Promise((resolve, reject) => {
});
// the VB application save can be controlled by either resolving or rejecting this promise.
// Resolving it would allow the save process, and rejecting the promise will cancel
the save process inside VB.
// The save process in VB will wait until this promise is resolved or rejected.
});
The following code sample shows an example in JavaScript for subscribing to OnBeforeSave
event:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
const tabContext = await frameworkProvider.getTabContext();
const recordContext = await tabContext.getActiveRecord();
const requestObject =
frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnBeforeSaveEvent');
recordContext.subscribe(requestObject, (response) => {
// custom code
return new Promise((resolve, reject) => {
});
// the VB application save can be controlled by either resolving or rejecting this promise.
// Resolving it would allow the save process and rejecting the promise will cancel the save process inside VB.
// The save process will wait until this promise is resolved or rejected.
});