• 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

    Obtain value of point in javascript.

    User help
    4
    8
    1.9k
    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.
    • J
      johana crisbany gamez
      last edited by

      I need to get the value of a point in the javascript of my component, to perform some operations. In HTML, can I do with the ma-point value, but in javascript? Thank you

      1 Reply Last reply Reply Quote 0
      • MattFoxM
        MattFox
        last edited by

        You can, but you'll have to do it with leveraging an angularjs controller and storing it in the userModule module.
        https://help.infiniteautomation.com/getting-started-with-a-user-module?rq=usermodule
        You'll have to use the maPointValues service. I'm not near a pc so I am unable to provide a code example at this time.

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        J 1 Reply Last reply Reply Quote 0
        • J
          johana crisbany gamez @MattFox
          last edited by

          @mattfox
          Yes, I have created my components. In a parent component, I filter the points that I need and in a child component, I bind the point I need. Now, I need to make a logic with the point value in javascript.
          I would appreciate an example of using the maPointValues ​​service, thanks!

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

            Johana:

            You might find this helpful. It is an example of a technique that I use in global scripts and scripting data sources.

            var query = "eq(deviceName," + source.name + ")&eq(name,Auto Limit)";
            var dataPoint = DataPointQuery.query( query );
            if( dataPoint.size() )
            {
                limit = dataPoint[0].runtime.value;
            }
            else
            {
                LOG.info( source.name + ": Auto Throttle: Auto Limit data point not found ");
                return;
            }
            

            I am not sure whether this works in your context, but perhaps it might be helpful.

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

              @MattFox

              Does the code above not work inside a module?

              MattFoxM 1 Reply Last reply Reply Quote 0
              • MattFoxM
                MattFox @pyeager
                last edited by MattFox

                @pyeager said in Obtain value of point in javascript.:

                @MattFox

                Does the code above not work inside a module?

                No, this JavaScript is what runs inside rhino nashorn and has access to Java methods (Hence the data point wrapper). The mango ui uses the rest api, hence why 3.6 can use the new ui to make various data sources and events and 3.5 cannot.

                For the code! Running on a few hours sleep here..

                componentContriller.$inject=['maPointValues'];
                
                function componentController(maPointValues)
                {
                var opts={
                latest:1,
                fields:['VALUE','TIMESTAMP','XID'],
                Rollup:'NONE'
                };
                 maPointValues.getPointValuesForXid('myXid',opts).then(function( values ){
                console.log( values );
                });
                }
                

                https://github.com/infiniteautomation/ma-dashboards/blob/main/UI/web-src/ngMango/services/pointValues.js

                I'm not certain if this is the right way to do it, bit it's 'a' way. You may find using the websockets and writing a handler to get the job done works better. YMMV

                Fox

                Do not follow where the path may lead; go instead where there is no path.
                And leave a trail - Muriel Strode

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

                  Thanks for helping out @MattFox and @pyeager

                  Couple comments,

                  No, this JavaScript is what runs inside rhino

                  It's now the Nashorn engine as of Java 8. If there are still Rhino references in the documentation I will remove them if I am aware of them.

                  On the global script comment, I would encourage using global scripts only for defining functions or global variables. It looks like it probably was on @pyeager 's system (otherwise 'source' is only going to be defined for Point Links and everything else will error while preparing the script engine), but that part may have been omitted.

                  I'm not certain if this is the right way to do it, bit it's 'a' way. You may find using the websockets and writing a handler to get the job done works better.

                  You could also define the point as an input of the component in its controller and then pass it in from existing components, such as was done in this thread: https://forum.infiniteautomation.com/topic/3503/how-to-chart-with-data-points-in-the-x-axis-instead-of-time/5

                  1 Reply Last reply Reply Quote 0
                  • MattFoxM
                    MattFox
                    last edited by MattFox

                    It's now the Nashorn engine as of Java 8

                    Noted!

                    Thanks Phil, you da MVP ;)

                    Do not follow where the path may lead; go instead where there is no path.
                    And leave a trail - Muriel Strode

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post