• 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

    Not a function

    Scripting general Discussion
    5
    18
    4.5k
    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.
    • Jared WiltshireJ
      Jared Wiltshire
      last edited by

      @Pedro @mihairosu I can confirm that the .get() method was removed from the starts and runtimes wrapper for the scripting context in Mango v3.4.0, it was listed in the release notes. However I am not sure why this change was made, I have asked the other developers to look at this.

      @pedro said in Not a function:

      After changing the syntax, the metadata javascript editor now issues the following warning: ['data'] is better written in dot notation

      How would I write this in 'dot notation?' Will the "Mango Java Script" help page be changed to illustrate the new syntax?

      Dot notation means writing this object.data rather than object['data'], they are 100% equivalent, the former is just more succinct.

      @pedro said in Not a function:

      I now have multiple IndexOutOfBoundsException errors. I believe it's a consequence of changing the metadata function syntax by inserting

      Yes its definitely caused by this change, previously the .get(true) method would loop over the list of starts and runtimes and return the starts and runtimes object for the value true. The object returned by .data now is a list which you would have to iterate over yourself.

      What does appear to work more like the previous behavior is something like this -
      if (OverVLimit.past(HOUR, 1).startsAndRuntime[true].proportion > 0) return 1;

      Developer at Radix IoT

      P 1 Reply Last reply Reply Quote 0
      • P
        Pedro @Jared Wiltshire
        last edited by

        @jared-wiltshire said in Not a function:

        I can confirm that the .get() method was removed from the starts and runtimes wrapper for the scripting context in Mango v3.4.0, it was listed in the release notes.

        Thanks, Jared. I did not see any mention of .get() removal in the release notes, including the meta release notes. Perhaps I looked in the wrong place. Can you please provide a link to those release notes so that I can read it in context?

        What does appear to work more like the previous behavior is something like this -
        if (OverVLimit.past(HOUR, 1).startsAndRuntime[true].proportion > 0) return 1;

        Thanks. I just tried that, and this is the result:
        Script error: TypeError: Cannot get property "proportion" of null in at line number 5 in at line number 5

        So it seems that in addition to finding and deleting get() from all my scripts, I need to figure out the equivalent syntax for each , and then check for null before proceeding with the intended use, then test each script. Then I have to figure out the syntax for other .get() functions, and check multiple combinations of data to make sure each new code still works. This is quite a hassle, as I have 25 .get() calls to find among 337 metadata scripts.

        The removal of .get() is clearly breaking many scripts. I'm looking forward to hearing why .get() was removed. If it can be put back in and released in the next week or so, I may be better off waiting for the new release rather than changing, debugging, and testing all those scripts. Since the Mango Java Script online documentation still shows .get(), I have some hope that this functionality will be restored in the next release. When do you reckon the next release will be? I also have to weigh this against a version rollback.

        Thanks.

        1 Reply Last reply Reply Quote 0
        • P
          Pedro
          last edited by

          @jared-wiltshire said in Not a function:

          startsAndRuntime

          I found it under the core release notes:

          Removing get(object) and get(DataValue) from StartsAndRuntimeList javascript wrapper so these methods are no longer available and should never have been used

          Still wondering why the abrupt removal. I hope the documentation is changed to illustrate what to use instead.

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

            Pedro,

            We removed that method because it was ambiguous as it required java to cast the argument to a Mango DataValue. This could be dangerous as Javascript has no concept of Integer vs. Double and supplying a 1.0 vs a 1 to the get() method could result in a failure on the backend.

            The new way to get the same information as described above will require you to check for null as if that state has not occurred in that period there will be no proportion member on a null object.

            The documentation will be updated and put out in our next release which should be in a week or two.

            P 1 Reply Last reply Reply Quote 0
            • P
              Pedro @terrypacker
              last edited by

              @terrypacker Thanks for the clarification.

              I'm sure users would be grateful if there were a couple of different examples of the new usage in the context help, including a warning about the potential to return null. It seems that any calls where .proportion or .percentage returned a 0 will now fail, and must be preceded by a check for null before the method is called.

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

                @Pedro we will add a new method for the next release that can be used like this:

                (OverVLimit.past(HOUR, 1).startsAndRuntime[true].proportion
                

                which will return a 0 percentage/proportion instead of null for convenience.

                P 1 Reply Last reply Reply Quote 0
                • P
                  Pedro @terrypacker
                  last edited by

                  @terrypacker Thanks, that would be handy. Currently I have to add three lines of code to each .proportion or .percentage call. Some of the scripts run only at the end of the month, so with luck I'll be able to upgrade before the end of the month and edit those scripts before the month is up. Now I'm editing the scripts that run every minute.

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

                    @Pedro after further discussion we will NOT be adding a method to avoid a null result. Take the example of a multistate point that has 3 states 1,2,3. If you request the time spent in state 4, you should get a null result. I believe you could use the Global Scripts module to define a method you can call in one line to achieve the non-null result of 0.

                    P 1 Reply Last reply Reply Quote 0
                    • P
                      Pedro @terrypacker
                      last edited by

                      @terrypacker Okay, thanks for the forewarning.

                      1 Reply Last reply Reply Quote 0
                      • Jared WiltshireJ
                        Jared Wiltshire @Pedro
                        last edited by

                        @pedro said in Not a function:

                        I have to add three lines of code to each .proportion or .percentage call.

                        One line, probably more readable to put a function in a global script though.

                        if ((OverVLimit.past(HOUR, 1).startsAndRuntime[true] || {proportion: 0}).proportion > 0)
                        

                        Developer at Radix IoT

                        1 Reply Last reply Reply Quote 0
                        • phildunlapP
                          phildunlap
                          last edited by phildunlap

                          @Pedro

                          After even further discussion we will be adding the get() function back in. It will work for multistate and binary points to get the StartsAndRuntime object for that state, and it will return a 0 starts, 0 proportion, 0 runtime object for states that did not occur. To check if a state is present in a statistics object, therefore, one can check that (if they feel it is distinct to their scripts' logic) by .past(HOUR, 1).startsAndRuntime[true] == null

                          Sorry for any inconvenience this caused.

                          Edit: Here is the example from the JavaScript help internal to Mango,

                              var stats = b.past(MONTH, 2);
                              var sar = stats.get(false).proportion; //get the proportion of time in false whether or not false occurred
                              var stateNotNull = stats.getStartsAndRuntime().containsKey(false); //see if false occurred
                          

                          and here is the help page's example, https://help.infiniteautomation.com/about-mango-java-script/

                          return b.past(MONTH, 2).get(false).proportion;
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post