• 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

    Script breaking as of 10/16/2019

    Scripting general Discussion
    2
    5
    1.6k
    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
      mihairosu
      last edited by mihairosu

      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
      
      1 Reply Last reply Reply Quote 1
      • terrypackerT
        terrypacker
        last edited by

        @mihairosu

        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.

        1 Reply Last reply Reply Quote 0
        • M
          mihairosu
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • M
            mihairosu
            last edited by

            The scripts worked fine over the weekend. Thanks for the help Terry.

            1 Reply Last reply Reply Quote 0
            • M
              mihairosu
              last edited by

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