---
title: "The getListValue( ) Function"
canonical: "https://docs.infoblox.com/space/NCSG/23199984/The%20getListValue(%20)%20Function"
format: markdown
---
A function for a CCS script to look up values in a list. The list must be installed in the NetMRI appliance (**Configuration** **Management** **–>** **Job** **Management** tab **–>** **Lists** page) to be referenced by scripts. For the given list name and the first specified column in the lookup, CCS finds the first row containing a defined matching value, and fetches the corresponding row's value from another data column in the same data record.

The parameters in `getListValue( )` are the following:

`getListValue(<list_name> <key_column> <key_value> <value_lookup_column> <default>)`

|  |  |
| --- | --- |
| `<list_name>` | The name of the list in the NetMRI Lists page. |
| `<key_column>` | The list column to search for the matching value in `<key_value>`. The specified column can be any column in the table. |
| `<key_value>` | The value to search for in the first `<key_column>` list column. |
| `<value_lookup_column>` | The location in the matching data record, in the list, to look up the value. |
| `<default> ` | The default message should no matching value appear in the list for  
`<key_value>`. If specifying no `<default>`, the argument `null` must be used. An example of a default message would be NOT_FOUND. |

**Example**

`Action-Commands:{$location eq "West"}`

` SET: $syslog1 = getListValue(NetworkServers,Server,WS1,IPAddr,null) `

`SET: $syslog2 = getListValue(NetworkServers,Server,WS2,IPAddr,null)`

Above, an `Action-Command` is called by the script if the value in the variable `$location` is equal to "West." Then, the script declares two SET variables, which use the `getListValue( )` to fetch specific values from the `NetworkServers` list. As an example, that list has three data columns: `Location`, `Server` and `IPAddr`.

| **Location** | **Server** | **IPAddr** |
| --- | --- | --- |
| West | WS1 | 220.11.113.246 |
| Southwest | WS3 | 210.15.200.246 |
| Asiapac | AS1 | 132.55.210.246 |
| Northeast | NS1 | 212.46.155.246 |
| East | NS2 | 212.46.156.246 |
| Midwest | MW1 | 210.15.205.246 |
| Southeast | NS3 | 212.46.154.246 |
| Midwest | MW2 | 210.15.206.146 |
| West | WS2 | 220.11.114.246 |
| South | SS1 | 180.99.99.246 |
| EMEA | EM1 | 133.10.1.246 |

  
 The variable `$syslog1` is written with the value `220.11.113.246`, because the script is told to open the list and search for the value `WS1` in the list's column labeled `Server`.

Finding `WS1` in the first row of the list, the script is directed to extract the value in that row's corresponding `IPAddr` column and write that IP value into `$syslog1`. The result is that the variable `$Syslog1 = 220.11.113.246`.

The second variable `$syslog2` works in similar fashion, getting written with the value `220.11.114.246`. When the script matches `WS2` in the list, the script is told to extract the value in that row's corresponding `IPAddr` column and write that into `$syslog2`.

---

**Note:** For all list operations, should you need to access a list as part of script operation, make sure that all changes to the list are saved (adding and deleting rows, changing column header names or moving columns, adding new data columns) before attempting to access the list again.

---

Another example, showing an entire script that updates the host names of devices from a list using old and new host names:  
 `Script-Filter:`

`$Vendor eq "Cisco"`

`########################`

` Action:`

`Get Device`

`Action-Description:`

`Get the old Host Name from the list and replace it with the new one. `

`Action-Commands:`

`SET: $new = getListValue(my_newhostname,old_name,$name,newhostname,NOTFOUND)`

`Action-Commands:{$new ne "NOTFOUND"} config t`

`hostname $new end`

`wr mem`

The list `my_newhostname` could be of any length; the example here is quite brief:

| **old_name** | **newhostname** |
| --- | --- |
| Wan-Router | Wan-Router2 |
| router-10-66-20-66 | EMEA_gateway |
| router-10-66-20-225 | Asiapac_gateway |