Script breaking as of 10/16/2019
-
This script used to work just fine, but is throwing errors every night since 10/16/2019 at the exact time its running 23:59:57.
/* //Script by Phil Dunlap to automatically generate lost history if( my.time + 60000 < source.time ) { //We're at least a minute after var metaEditDwr = new com.serotonin.m2m2.meta.MetaEditDwr(); metaEditDwr.generateMetaPointHistory( my.getDataPointWrapper().getId(), my.time+1, CONTEXT.getRuntime(), false); //Arguments are, dataPointId, long from, long to, boolean deleteExistingData //my.time+1 because first argument is inclusive, and we have value there } //Your regular script here.*/ return CwConsumed.value-CwConsumed.ago(DAY, 1) //Subtracts this moment's gallons used minus one day ago
Here's the error:
'MetaDataSource': Script error in point "Main Historian - DHW Consumed Daily Count": Expected } but found eof return DhwConsumed.value-DhwConsumed.ago(DAY, 1) //Subtracts this moment's gallons used minus one day ago ^ at line: 12, column: 129Add comment
-
I assume you upgraded to Mango 3.6 and then the script started breaking but you did not say that. The reason it no longer works is because in Mango 3.6 we wrap all Meta scripts in a function block and then execute the function. So when you use your script it actually gets translated (internally in Mango) into this code:
function __scriptExecutor__() { /* //Script by Phil Dunlap to automatically generate lost history if( my.time + 60000 < source.time ) { //We're at least a minute after var metaEditDwr = new com.serotonin.m2m2.meta.MetaEditDwr(); metaEditDwr.generateMetaPointHistory( my.getDataPointWrapper().getId(), my.time+1, CONTEXT.getRuntime(), false); //Arguments are, dataPointId, long from, long to, boolean deleteExistingData //my.time+1 because first argument is inclusive, and we have value there } //Your regular script here.*/ return CwConsumed.value-CwConsumed.ago(DAY, 1); //Subtracts this moment's gallons used minus one day ago } __scriptExecutor__();
As you can see the last line in your function get the end of the function appended
}
and then executed__scriptExecutor__();
Since your last line contains a comment the end of the wrapping function and the actual command to execute it are commented out causing the problem. The reason for doing it this way is because it makes the validation and testing messages for scripts easier to relate to the script being tested as the Javascript engine returns the line number and column number of the failure. I will take a look at making this more robust in Mango 3.7.0.
So just remove the commend from the end of the last line and place it above the line to get this to work.
-
I can't confirm 100% is was on that day, but it's very possible, which is why I didn't mention it, but you are probably right.
I will make these changes and get back to you.
-
The scripts worked fine over the weekend. Thanks for the help Terry.
-
Hey Terry,
This one is also giving a java out of bounds exception, but I don't understand why:
/* //Script by Phil Dunlap to automatically generate lost history if( my.time + 60000 < source.time ) { //We're at least a minute after var metaEditDwr = new com.serotonin.m2m2.meta.MetaEditDwr(); metaEditDwr.generateMetaPointHistory( my.getDataPointWrapper().getId(), my.time+1, CONTEXT.getRuntime(), false); //Arguments are, dataPointId, long from, long to, boolean deleteExistingData //my.time+1 because first argument is inclusive, and we have value there } //Your regular script here.*/ //Get daily run starts return runs.past(MINUTE, 1440)['data'].get(true).starts;