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

Change point value via script


  • I'm trying to create a button which is when button clicked it will set multiple point values. I look for relevant question in this forum, unfortunately it doesnt work for me. Any help is very appreciated. Here is my code.

     <a id="476838d4-4ac0-4562-84c8-787a0f341fc1" style="position: absolute; left: 806px; top: 86px; width: 221.266px; height: 44.9063px; z-index: 3; color: rgba(255,56,47);" href="#" onclick="call_this()">Occupied</a>
         
        <script type="text/javascript">
           function call_this()
           {
               var tags = com.serotonin.m2m2.db.dao.DataPointTagsDao.instance.getTagsForDataPointId( p.getDataPointWrapper().getId() );
               var newTags = {"tags.TmpSpvCoSpvClg":"20"};
                    CONTEXT_POINTS.p.getVO().setTags(newTags); 
                    com.serotonin.m2m2.db.dao.DataPointDao.instance.saveDataPoint(CONTEXT_POINTS.p.getVO());
                
           
           }
    

  • If you're trying to do this from the dashboard it's not gonna work;
    Scripts have to be executed within an angularJS controller;
    The best thing by far you can do is to use the ma-get-point-value component.
    I'm making three assumptions here:

    1. You know which points you want to alter
      2)These points will not change - ie this page is static and does not need further amendments regarding the points you wish to set.
      3)You are using mango version 3 with the mangoUI dashboards
    <!--  1 get the points xid value and use it in the ma-get-point-value -->
    
    <ma-get-point-value point-xid="DP_myPointXID" point="point1"></ma-get-point-value>
    <ma-get-point-value point-xid="DP_my2ndPointXID" point="point2"></ma-get-point-value>
    
    

    You can find the point xid via the [mango domain]/data_sources.shtm page:
    0_1557725922061_728f9699-3823-4c30-bc57-1b1bcc1cb0b3-image.png

    2)next: get your ma-button directive and use angular's ng-click event to set the points.
    This is a bit crude but if you have little or no programming experience it's certainly one way of doing what you desire.

    <ma-button label="Set Points" tooltip="Sets these points to '1'" raised="true" hue="hue-2" palette="primary" ng-click="point1.setValue('1'); point2.setValue('1');"></ma-button>
    

    Together it looks like this:

    <!--  1 get the points xid value and use it in the ma-get-point-value -->
    
    <ma-get-point-value point-xid="DP_myPointXID" point="point1"></ma-get-point-value>
    <ma-get-point-value point-xid="DP_my2ndPointXID" point="point2"></ma-get-point-value>
    <!-- 2 add button with angular on click event -->
    <ma-button label="Set Points" tooltip="Sets these points to '1'" raised="true" hue="hue-2" palette="primary" ng-click="point1.setValue('1'); point2.setValue('1');"></ma-button>
    
    

    Good Luck

    Fox


  • Hi James,

    It looks to me like you're changing tags, not values. You could do this through the /rest/v2/data-points API or the /rest/v2/script/run endpoint if you were wanting to use a script. You do not need to preface the tag with tags. and you should go through the DataPointWrapper to ensure the tags are loaded, so currently you'd reference it like p.getDataPointWrapper().tags["tags.TmpSpvCoSpvClg"] which is probably not ideal. You can explore the API using swagger if it's enabled in your env.properties file at startup on the /swagger-ui.html page.

    Thanks Fox for the samples if indeed he does mean point values!


  • NP, although looking at what you've stated, I've missed the mark completely... I thought he was trying to do a dashboard page, unless you're telling me the com library is in the dashboard too....


  • In your defense he did say,

    I'm trying to create a button which is when button clicked it will set multiple point values.

    But CONTEXT_POINTS and com.serotonin are definitely not features in dashboards, and exist in Mango JavaScript environments on the server side.