# String key/value constraint edit and replace

**URL:** <https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438>\
**Category:** Automation & Control\
**Created:** [May 20, 2020, 9:59am UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438 "2020-05-20T09:59:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexsamih-zade](https://rossvideo.community/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@alexsamih-zade](https://rossvideo.community/u/alexsamih-zade)\
**Post date:** [May 20, 2020, 9:59am UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/1 "2020-05-20T09:59:00Z")

</div>

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());

---

<div class="post-metadata">

**Author:** ![ericwang](https://rossvideo.community/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@ericwang](https://rossvideo.community/u/ericwang)\
**Post date:** [May 21, 2020, 9:31pm UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/2 "2020-05-21T21:31:00Z")

</div>

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](https://livinglive.community/search?s=tags%3A%22DashBoard%22&executesearch=true)

---

<div class="post-metadata">

**Author:** ![alexsamih-zade](https://rossvideo.community/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@alexsamih-zade](https://rossvideo.community/u/alexsamih-zade)\
**Post date:** [May 21, 2020, 10:45pm UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/3 "2020-05-21T22:45:00Z")

</div>

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](https://livinglive.community/search?s=tags%3A%22DashBoard%22&executesearch=true)

---

<div class="post-metadata">

**Author:** ![ericwang](https://rossvideo.community/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@ericwang](https://rossvideo.community/u/ericwang)\
**Post date:** [May 22, 2020, 12:36am UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/4 "2020-05-22T00:36:00Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![alexsamih-zade](https://rossvideo.community/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@alexsamih-zade](https://rossvideo.community/u/alexsamih-zade)\
**Post date:** [May 22, 2020, 12:42am UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/5 "2020-05-22T00:42:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![alexsamih-zade](https://rossvideo.community/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@alexsamih-zade](https://rossvideo.community/u/alexsamih-zade)\
**Post date:** [May 22, 2020, 4:56pm UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/6 "2020-05-22T16:56:00Z")

</div>

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](https://livinglive.community/search?s=tags%3A%22DashBoard%22&executesearch=true)

---

<div class="post-metadata">

**Author:** ![ericwang](https://rossvideo.community/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@ericwang](https://rossvideo.community/u/ericwang)\
**Post date:** [May 23, 2020, 8:03am UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/7 "2020-05-23T08:03:00Z")

</div>

Hi Alex,

You can get that value by changing

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

---

<div class="post-metadata">

**Author:** ![alexsamih-zade](https://rossvideo.community/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@alexsamih-zade](https://rossvideo.community/u/alexsamih-zade)\
**Post date:** [May 23, 2020, 5:00pm UTC](https://rossvideo.community/t/string-key-value-constraint-edit-and-replace/8438/8 "2020-05-23T17:00:00Z")

</div>

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

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