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.
How to get event instance data as object using Script Event Handler
-
Hello everyone,
We started exploring new scripting environment and currently trying to use Script Event Handlers instead of Set Point Event Handlers (Set To Scripted Value). We are be able to use the evt variable in global scripts with the code in below
function myHandler(evt) { var point = evt.context.point; var pointXid = evt.context.point.xid; var pointTags = point.tags;
But in the new Script Event Handler the evt variable returns a string. Is there a way to format evt variable into a proper object or do we need to do this in a different way in the new scripting environment?
Thanks,
Mert -
I figured out how to do it by using java class methods in ma-core-public.
const DataSourceDao = Java.type('com.serotonin.m2m2.db.dao.DataSourceDao'); function myHandler(evt) { var point = evt.getContext().context.get("point"); var pointXid = point.getXid(); var pointTags = point.getTags(); var dataSourceXid = point.getDataSourceXid(); var ip = DataSourceDao.getInstance().getByXid(dataSourceXid).getHost();
-
@mert sorry for the delay. Another option would be to use the Service that is injected into the context like this:
const dataSourceService = services.dataSourceService; const ip = dataSourceService.get('xid');
Also here is a collection of example scripts for the new environment and a few for the legacy one: