• 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

    Accessing a points tag value via script?

    User help
    2
    7
    1.8k
    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.
    • W
      Wingnut2.0
      last edited by

      Is it possible to access a data points tag value in a script?

      "tags": {
          "breaker_size": "20"
        }
      

      I did not see the tags listed when using print(point). Curious if it's possible and if so the required syntax.

      Thank you.

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

        Hi Wingnut2.0,

        At the moment you'll have to do,

        var tags = com.serotonin.m2m2.db.dao.DataPointTagsDao.instance.getTagsForDataPointId( p.getDataPointWrapper().getId() );

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

          I have made the p.getDataPointWrapper().getTags() function load the tags if they're null.

          1 Reply Last reply Reply Quote 0
          • W
            Wingnut2.0
            last edited by

            Thank you, Phillip. Exactly what I needed.

            Using your example I can easily retrieve a specific tag -

            tags.breaker_size;
            

            Next question is can I write to a tag using this function and is the there any history associated with a given tags value?

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

              You could set a points tags either by setting the running data point to have the new tags and saving them, like so,

              var newTags = {"key":"value"};
              CONTEXT_POINTS.p.getVO().setTags(newTags);
              com.serotonin.m2m2.db.dao.DataPointTagsDao.instance.saveDataPointTags(CONTEXT_POINTS.p.getVO());
              

              or you could save the whole point, like so,

              var newTags = {"key":"value"};
              CONTEXT_POINTS.p.getVO().setTags(newTags);
              com.serotonin.m2m2.db.dao.DataPointDao.instance.saveDataPoint(CONTEXT_POINTS.p.getVO());
              

              Currently the first option is not generating audit events for the tags, but the second option would. The downside of the second option is that it requires restarting the data point. Then you can see the tag history in the audit table. I have created this issue about the first option not generating audit events: https://github.com/infiniteautomation/ma-core-public/issues/1267

              1 Reply Last reply Reply Quote 0
              • W
                Wingnut2.0
                last edited by

                @phildunlap said in Accessing a points tag value via script?:

                setTags

                Works perfectly for creating new tags. Is there another approach to update the value of an existing tag?
                Right now if I use this approach I need to re-write all tags & values or I will loose them. For example, if I have 4 tags for a given point and use this approach to set (update) only one of the tags value, the other tags get wiped out.

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

                  Yes, that is true. So, you would want to update the tag in the existing tags map, then, like,

                  var tags = com.serotonin.m2m2.db.dao.DataPointTagsDao.instance.getTagsForDataPointId( p.getDataPointWrapper().getId() );
                  tags.key = "value";
                  CONTEXT_POINTS.p.getVO().setTags(tags);
                  com.serotonin.m2m2.db.dao.DataPointDao.instance.saveDataPoint(CONTEXT_POINTS.p.getVO());
                  

                  There are not methods to update a tag individually of the other tags. The DataPointTagsDao takes the whole DataPointVO as its argument.

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