Facility Control

 View Only
  • 1.  String key/value constraint edit and replace

    Posted 05-20-2020 05:59

    Hello,

    I have an String key/value constraint , and i want to add new values to it. So, i need to read all existing key/value pairs, and add to the new one. But i lost in how to read the values - i only have succeed with names (using getChoices), and i can read the selected value - but not all values.. 

    How to achieve that? 

    Thank you!

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="IP" oid="IP" type="STRING" value="192.168.2.45" widget="radio-toggle">
    <constraint key="192.168.2.43">Camera-1</constraint>
    <constraint key="192.168.2.45">Camera-2</constraint>
    </param>
    <param access="1" maxlength="0" name="newIp" oid="newIp" type="STRING" value="" widget="default"/>
    <param access="1" maxlength="0" name="newName" oid="newName" type="STRING" value="" widget="default"/>
    </params>
    </meta>
    <param expand="true" height="40" left="60" oid="IP" style="t:style:navigationButton;f:style:navigationButton;" top="40" width="920">
    <task tasktype="ogscript">ogscript.debug(this.getValue());</task>
    </param>
    <abs height="60" left="60" top="100" width="360">
    <label height="20" left="0" name="Add/Delete to parameter constrain:" style="txt-align:center;size:Big;" top="0" width="320"/>
    <param expand="true" height="20" left="220" oid="newIp" top="40" width="120"/>
    <param expand="true" height="20" left="40" oid="newName" top="40" width="140"/>
    <label height="20" left="0" name="Name" style="txt-align:west" top="40" width="40"/>
    <label height="20" left="200" name="IP:" style="txt-align:west;" top="40" width="20"/>
    </abs>
    <button buttontype="push" height="20" left="420" name="add" top="140" width="60"/>
    </abs>

     



  • 2.  RE: String key/value constraint edit and replace

    Posted 05-21-2020 17:31

    Hi alex, 

    You can get all the values you need in a for loop and use the getValues() API of single constraint. I will post an example below for you to refer.

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" id="_top" keepalive="false" style="">

       <meta>

          <params>

             <param access="1" constrainttype="INT_CHOICE" name="paramIntFibonacci" oid="paramIntFibonacci" precision="0" type="INT32" value="21" widget="default">

                <constraint key="1">one</constraint>

                <constraint key="2">two</constraint>

                <constraint key="3">three</constraint>

                <constraint key="5">five</constraint>

                <constraint key="8">eight</constraint>

                <constraint key="13">thirteen</constraint>

                <constraint key="21">twentyone</constraint>

             </param>

          </params>

       </meta>

       <param expand="true" height="533" left="25" oid="paramIntFibonacci" showlabel="false" top="236" widget="list" width="171"/>

       <button buttontype="push" height="68" left="219" name="List Constraints" top="225" width="261">

          <task tasktype="ogscript">var numList = params.getConstraint("paramIntFibonacci");

    var choices = numList.getChoices();

    var output = "Constraints are:";

    for (var i = 0; i &lt; choices.length; i++) {

       output = output + "\nitem " + choices[i].getValue() + " = " + choices[i].getName();   

    }

    ogscript.rename("output", output);</task>

       </button>

       <label height="445" id="output" left="220" name="Constraints are:" style="txt-align:north;bdr:line;" top="307" width="257"/>

       <label height="60" left="40" name="Getting Constraints and Listing Them Example" style="txt-align:west;size:Bigger;" top="40" width="620"/>

       <label height="20" left="40" name="You can get the constraints from a parameter, loop through them and do something with them." style="txt-align:west;" top="100" width="1100"/>

       <label height="20" left="40" name="In this case, when the button is clicked, it simply lists them in the box below the button." style="txt-align:west;" top="120" width="1120"/>

    </abs>
    Cheers. 

     


    #DashBoard


  • 3.  RE: String key/value constraint edit and replace

    Posted 05-21-2020 18:45

    Hello Eric and thank you for the answer
    Your code is good for constrainttype="INT_CHOICE" yype of parameter. In my case, i use constrainttype="STRING_STRING_CHOICE" type, so the getValues() doesn't work for that one..


    #DashBoard


  • 4.  RE: String key/value constraint edit and replace

    Posted 05-21-2020 20:36

    Hi alex

    I recommend using getValue() instead of getValues() for single choice, and then you can using a for loop to get the values. 

    The code below is based on your code about how to get the IP and camera names.

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="IP" oid="IP" type="STRING" value="192.168.2.45" widget="radio-toggle">
    <constraint key="192.168.2.43">Camera-1</constraint>
    <constraint key="192.168.2.45">Camera-2</constraint>
    </param>
    <param access="1" maxlength="0" name="newIp" oid="newIp" type="STRING" value="" widget="default"/>
    <param access="1" maxlength="0" name="newName" oid="newName" type="STRING" value="" widget="default"/>
    </params>
    </meta>
    <param expand="true" height="40" left="60" oid="IP" style="t:style:navigationButton;f:style:navigationButton;" top="40" width="920">
    <task tasktype="ogscript">ogscript.debug(this.getValue());

    var strList = params.getConstraint("IP");

    var choices = strList.getChoices();

    var output = "Constraints are:";

    for (var i = 0; i &lt; choices.length; i++)
    {
    output = output + "\nitem " + choices[i].getValue() + " = " + choices[i].getName();
    ogscript.debug(output)
    }</task>
    </param>
    <abs height="60" left="60" top="100" width="360">
    <label height="20" left="0" name="Add/Delete to parameter constrain:" style="txt-align:center;size:Big;" top="0" width="320"/>
    <param expand="true" height="20" left="220" oid="newIp" top="40" width="120"/>
    <param expand="true" height="20" left="40" oid="newName" top="40" width="140"/>
    <label height="20" left="0" name="Name" style="txt-align:west" top="40" width="40"/>
    <label height="20" left="200" name="IP:" style="txt-align:west;" top="40" width="20"/>
    </abs>
    <button buttontype="push" height="20" left="420" name="add" top="140" width="60"/>
    </abs>

    #DashBoard


  • 5.  RE: String key/value constraint edit and replace

    Posted 05-21-2020 20:42

    Thanks, i did the same but without succeess.. i guess i missed something. Will check it tommorow. Thank you very much!


    #DashBoard


  • 6.  RE: String key/value constraint edit and replace

    Posted 05-22-2020 12:56

    Ok, i just checked that code - and its doesnt working. I got in debug:
    item 0 = Camera-1
    item 0 = Camera-2

    (i did the same and  got the same results before posting that post)

    While i expect to get:

    192.168.2.43= Camera-1
    192.168.2.45 = Camera-2

    Did you checked your code and got that values? I'm running the last 9.02 version of dashboard. 


    #DashBoard


  • 7.  RE: String key/value constraint edit and replace

    Posted 05-23-2020 04:03

    Hi Alex,

    You can get that value by changing

    choices[i].getValue() to choices[i].getValueString()

    #DashBoard


  • 8.  RE: String key/value constraint edit and replace

    Posted 05-23-2020 13:00

    Hello, Eric, thank you, choices[i].getValueString() is work!


    #DashBoard