• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Which Point Called Event Handler?

    Scripting general Discussion
    2
    4
    897
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      marganellim
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • terrypackerT
        terrypacker
        last edited by

        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
        
        M 1 Reply Last reply Reply Quote 0
        • M
          marganellim @terrypacker
          last edited by marganellim

          @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
          Screenshot from 2021-10-27 16-11-33.png

          terrypackerT 1 Reply Last reply Reply Quote 0
          • terrypackerT
            terrypacker @marganellim
            last edited by terrypacker

            @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);
            }
            
            
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post