View Events
Ometa provides several event hooks to execute functions in runtime.
General
OnLoadComplete
This event is triggered after all data sources have been loaded.
OnRealtimeAction
This event triggers when a realtime action occurs. You get access to the action that is triggered, including the new data.
Argument | Type | Description |
---|---|---|
componentId | string | The component id. |
view | CreateView | UpdateView | The view configuration. |
CSL | CustomScriptingLibrary | The custom scripting library. |
realtimeAction | RealtimeAction | The action that is triggered. This includes what kind of action occurs (Create, Update, Delete) and the data that is used. |
To prevent the realtime action to take action on the ADM, return false.
Example:
// Only allow active products to update realtime.
return realtimeAction.data.productActive === true;
Create and Update
Both the create and update views, support the following events on top of the general events:
- AfterSaveAlways
- AfterSaveError
- AfterSaveSuccess
- BeforeSave
- OnLoadForm
AfterSaveAlways
The after save always event is triggered every time the form is saved. This event is executed after the after save success or after save error events.
If you are using the after save error event in an item function, the event is triggered for each record.
Argument | Type | Description |
---|---|---|
componentId | string | The component id. |
view | CreateView | UpdateView | The view configuration. |
rowData | Object | The initial form values extended with optional row and cm context. |
CSL | CustomScriptingLibrary | The custom scripting library. |
AfterSaveError
The after save error event is triggered after a user clicks the save button and when there is any error from the external system. This includes any technical or functional error from the external system. This event supports asynchronous code.
If you are using the after save error event in an item function, the event is triggered each time the method goes wrong.
It is possible to return error messages by throwing or rejecting a promise.
Argument | Type | Description |
---|---|---|
componentId | string | The component id. |
view | CreateView | UpdateView | The view configuration. |
rowData | Object | The initial form values extended with optional row and cm context. |
error | string | The error returned by the method. |
CSL | CustomScriptingLibrary | The custom scripting library. |
// It is possible to return custom error messages.
// Use `throw` when you have synchronous code.
// The rowData parameter can be used to personalise the message on the current failed record.
if (error === 'Some error from the external system') {
throw `My custom error message for item ${rowData.Name}`.
}
// When you have asynchronous code you can work with Promises. Resolving the promise however, will do nothing.
Promise.reject('My custom error message');
AfterSaveSuccess
The after save success event is triggered after a user clicks the save button and when the view is executed successfuly. This event supports asynchronous code.
If you are using the after save success event in an item function, the event is triggered each time the method is successful.
It is possible to return custom success messages by returning a string.
Argument | Type | Description |
---|---|---|
componentId | string | The component id. |
view | CreateView | UpdateView | The view configuration. |
rowData | Object | The output fields returned by the method. |
CSL | CustomScriptingLibrary | The custom scripting library. |
// You can do something with the output fields returned by the method.
console.log(rowData);
// It is possible to return custom success messages.
return "My custom success message.";
// Or with some async code.
return Promise.resolve("My custom success message");
BeforeSave
This event is triggered before the view is executed.
It is possible to cancel the save:
- By returning a Promise that rejects. If a string is send with the rejection, the string will be used as error message. If there is no string provided, the user will not be notified that the save was canceled.
- By throwing an error. The string provided in the throw will be used as error message.
- By returning false. This is not recomended. The user will not be notified that the save was canceled.
It is possible to overwrite the values that are used for the save.
- By returning an object.
- By resolving a Promise with an object.
Argument | Type | Description |
---|---|---|
componentId | string | The component id. |
view | CreateView | UpdateView | The view configuration. |
rowData | Object | The form values. |
CSL | CustomScriptingLibrary | The custom scripting library. |
// Example where an exception is thrown.
let minimumAge = new Date();
minimumAge.setFullYear(minimumAge.getFullYear() - 18);
if (minimumAge < rowData["Date of Birth"]) {
throw "You must be 18 years or older";
}
// Example where a promise is used with some async code.
return new Promise((resolve, reject) => {
fetch(`external resource`).then(response => {
resolve();
}).catch(err => {
// If 'err' is a string, 'err' will be used as error message.
reject(err);
}
});
// Example where you immediately reject the promise.
return Promise.reject("My custom error message");
// Supported but not preferred!
return false;
// Overwrite the values used in the save.
return { productName: "ABC123" };
// Example where a promise is used with some async code.
return new Promise((resolve, reject) => {
fetch(`external resource`).then(response => {
// Overwrite the values used in the save.
resolve({productName: 'ABC123'});
}).catch(err => { reject(err); }
});
OnLoadForm
Currently not supported.