Adding JavaScript
Add new entries to your Audit Trail using a JavaScript function. This allows all interactions with the interface to be logged.
Adding a JavaScript in Visual Studio / TcXaeShell
- 1. Add a new JavaScript file to the project.
- 2. Open the JavaScript file you have created.
- 3. Call the function TcHmi.Server.AuditTrail.createAuditLogEntryEx.
- This function adds a new entry to the audit trail.
Function - JavaScript:
TcHmi.Server.AuditTrail.createAuditLogEntryEx(
{
name: string,
contextDomain: string,
comment: string,
data: any
},
null,
(data) => {
}
);
Sample – JavaScript (Navigation Information):
(function (/** @type {globalThis.TcHmi} */ TcHmi) {
// If you want to unregister an event outside the event code you need to use the return value of the method register()
let destroyOnInitialized = TcHmi.EventProvider.register('onInitialized', (e, data) => {
// This event will be raised only once, so we can free resources.
// It's best practice to use destroy function of the event object within the callback function to avoid conflicts.
e.destroy();
let __this = this;
let destroyNavigationRightonPressed;
// Navigation_Right
TcHmi.EventProvider.register('Navigation_Right.onAttached', function (e, data) {
__this.controlNavigationRight = data;
// create event listener
destroyNavigationRightonPressed = TcHmi.EventProvider.register(`${data.__id}.onPressed`, function (e, data) {
TcHmi.Server.AuditTrail.createAuditLogEntryEx(
{
name: `Control Id: ${__this.controlNavigationRight.getId()}`,
contextDomain: `TriggeredUserInteraction`,
comment: `Navigation changed to "${__this.controlNavigationRight.getBreadcrumbPath().join(" || ")}" on ip ${TcHmi.Server.getCurrentUserConfig().clientIp}`,
data: { data: "Test" }
},
null,
(data) => {
}
);
});
});
TcHmi.EventProvider.register('Navigation_Right.onDetached', function (e, data) {
// destroy sub events
if (destroyNavigationRightonPressed) {
destroyNavigationRightonPressed();
destroyNavigationRightonPressed = undefined;
}
__this.controlNavigationRight = undefined;
});
});
})(TcHmi);