Which Point Called Event Handler?
-
Hello,
Sorry if this is a simple question but I cant seem to find the answer.
I have 70 points that all have event detectors connected to a single event handler that sends emails.
In addition to this email, I have a script that runs.
Within that script, is it possible to get the point XID or event detector XID that originally fired off the event handler?Thanks
-
In Mango 4 this script:
LOG.info('Source point xid: ' + model.point.xid); LOG.info('Source detector xid: ' + model.pointEventDetector.xid); return UNCHANGED;
Produces this output:
INFO 2021-10-25 08:29:09,725 - Source point xid: DP_495b84f1-ecda-4aef-9486-fa91b92c48e6 INFO 2021-10-25 08:29:09,738 - Source detector xid: ED_31d340c1-a979-4eba-b0c6-71eca7c50787
-
@terrypacker
Hi Terry, Thanks for the reply.
I tried this in both a global script and event handler script. In both cases, model is undefined. See below. Sorry for the quality, fonts are looking janky.
FYI. Running version 4.2.1
-
@marganellim the script I gave you is for the "script" section of the email event handler. That is the only place the "model" is included in the script context as it is normally used to modify the model that is used to generate the Email via the FTL template but you can do anything you want in that script.
The script you use will depend on the type of Event Handler you choose. If you want to use a "Script" Event Handler then this would work:
/** * This script implements com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface * Add this script to a "Script" type event handler and choose the Graal.js or Nashorn engine. */ /** * Called when the Mango event is raised. * You must implement this method. * * @param event */ function eventRaised(event) { console.log('Raised', event); console.log('test xid: ' + event.getContext().get('point').getXid()); } /** * Called when the Mango event is acknowledged (the event may still be active). * Supported as of Mango v4.0.0-beta.14, you are not required to implement this method. * * @param event */ function eventAcknowledged(event) { console.log('Acknowledged', event); } /** * Called when the Mango event returns to normal or is deactivated (e.g. on shutdown). * You must implement this method. * * @param event */ function eventInactive(event) { console.log('Inactive', event); }