String key/value constraint edit and replace

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!

Camera-1 Camera-2 ogscript.debug(this.getValue());

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"?>
  <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>
  <task tasktype="ogscript">var numList = params.getConstraint("paramIntFibonacci");

var choices = numList.getChoices();

var output = “Constraints are:”;

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

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

}

ogscript.rename(“output”, output);

Cheers.

#DashBoard

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

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.

Camera-1 Camera-2 ogscript.debug(this.getValue());

var strList = params.getConstraint(“IP”);

var choices = strList.getChoices();

var output = “Constraints are:”;

for (var i = 0; i < choices.length; i++)
{
output = output + "\nitem " + choices[i].getValue() + " = " + choices[i].getName();
ogscript.debug(output)
}

[#DashBoard](https://livinglive.community/search?s=tags%3A%22DashBoard%22&executesearch=true)

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

#DashBoard

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

Hi Alex,

You can get that value by changing

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

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

#DashBoard