Facility Control

 View Only
  • 1.  Removing a indexed parameter

    Posted 02-10-2017 12:21

    Anyone know why this doesn't work?? :(

    for (i = 0; i < teamNodes.length; i++) {
          if (params.getValue('homeTeamsID', i) == "x") {
             params.getParam('homeTeamsID', i).remove();
          };
       };

    There must be something wrong with [QUOTE]params.getParam('homeTeamsID', i).remove(); since I managed to set the value to something else if I change it to params.setValue...



  • 2.  RE: Removing a indexed parameter

    Posted 02-13-2017 15:57
    Hi Tobias.
    One thing that might be impacting you is that the number of nodes you have will change after you call remove so you might be running into problems there...
    A way to solve this would be to add a "break;" after you remove the param to exit your loop.
     
    <abs contexttype="opengear" style="">
       <meta>
          <params>
             <param access="1" maxlength="0" name="My Param" oid="params.myparam" precision="0" type="STRING_ARRAY" value="a;b;c;d;e;f;g;h;i" widget="default">
                <value>a</value>
                <value>b</value>
                <value>c</value>
                <value>d</value>
                <value>e</value>
                <value>f</value>
                <value>g</value>
                <value>h</value>
                <value>i</value>
             </param>
             <param access="1" constrainttype="STRING_CHOICE" name="Table" oid="params.table" precision="0" type="INT16" value="-1" widget="table">
                <constraint>params.myparam</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="486" left="18" oid="params.table" showlabel="false" top="33" width="395"/>
       <button buttontype="push" height="99" left="426" name="Remove G" top="33" width="211">
          <task tasktype="ogscript">var elemCount = params.getElementCount('params.myparam');
    for (var i = 0; i &lt; elemCount; i++)
    {
       var param = params.getParam('params.myparam', i);
       if (param.getValue() == 'g')
       {
          param.remove();
          break;
       }
    }</task>
       </button>
    </abs>
    Another option would be to use params.setAllValues. This would work if you are trying to remove multiple values or don't want to exit your loop until the end for some other reason:
    <button buttontype="push" height="99" left="426" name="Remove E" top="140" width="211">
       <task tasktype="ogscript">var elemCount = params.getElementCount('params.myparam');
    var newValues = [];
    for (var i = 0; i &lt; elemCount; i++)
    {
       var paramValue = params.getValue('params.myparam', i);
       if (paramValue != 'e')
       {
          newValues.push(paramValue);
       }
    }
    
    params.setAllValues('params.myparam', newValues);</task>
    </button>

    #DashBoard


  • 3.  RE: Removing a indexed parameter

    Posted 02-14-2017 14:28
    I actually found another way to set my parameter values which gets me around the issue of removing items. But this is still useful, thank you!
    #DashBoard