Is it possible to delete a point Value through scripting?
-
When I run a scripting data source and locate a point value of interest I know I can change that point value but can I delete it completely?
-
Hi Phillip,
This is not currently possible, but it's an interesting idea.
-
I should say there's not a direct way through the point, if you're on the latest, you could do....
var pointValueDao = com.serotonin.m2m2.Common.databaseProxy.newPointValueDao(); var data = p.pointValuesSince(CONTEXT.timestamp - CONTEXT.millisInPast(MONTH)); var pointId = com.serotonin.m2m2.db.dao.DataPointDao.instance.getDataPointIdByXid(p.getDataPointWrapper().xid); for(var k = 0; k < data.length; k+=1) { pointValueDao.deletePointValue(pointId, data[k].time); } print(data);
You'll notice the second time you run it, data is empty in the print. Also, be aware that if you invoke Java code directly (like I'm doing here), there is probably not going to be a distinction between 'validating' the script and running the script. So, this script will delete all point data in the last month from point p even when you are just pressing the validate button. Be careful.
-
@phildunlap OK I'll be extra careful with this one. Thanks for the quick reply.
Curiously Phil I searched mango's online help for deletePointValue and your reply was the ONLY reference to this method that came back and I'm wondering why this is so. More to my point where on earth can I find these references for the objects that seem to live in here obscurely somewhere?
CONTEXT,
com.serotonin.m2m2.Common.databaseProxy.newPointValueDao();
I would love to get a better handle on finding reference materials. -
The CONTEXT object was recently added to the contextual "Mango JavaScript" help dialogue, but I'm not sure the help page was updated. It's been around for a long time housing the runtime of the script and a few helper functions. The timetsamp was recently added for a particular purpose.
The second item,
com.serotonin.m2m2.Common.databaseProxy.newPointValueDao()
is actually a specific call into the Java code. The
com.serotonin.m2m2
is the package path to the class Common, which has member variable databaseProxy. The returned object is still a native Java object. There isn't documentation for this because it simply wouldn't be feasible. The code is open source, it's about the best we can do for direct references to the Java code.