Name-value pairs field type
reference australia Updated Nov 6, 2026 1 min read name-value-pair-scripting.md
You can access the values stored in a name-value pairs field in scripts using the name.
Sample script
The following example demonstrates how to add mappings to a name-value pairs field, and how to query existing values using the name.
JavaScript
// Script example demonstrating setting and getting valuesvar gr = new GlideRecord('u_nv_table');gr.initialize();
gr.nv_field.name1 = "value1"; //add a name-value Pair mapping with the name "name1" and value "value1"gr.nv_field.name2 = "value2"; //add another name-value Pair mapping with the name "name2" and value "value2"
// Access by dot notationgs.print("name1 = " + gr.nv_field.name1); // Expected output: name1 = value1
// Iterate over each property and print name and valuefor(var name in gr.nv_field) { gs.print(name + " = " + gr.nv_field[name]);}
gs.print(gr.nv_field); // Expected output: {"name1":"value1","name2":"value2"}40 lines · 1.4 KB
---
title: Name-value pairs field type
description: You can access the values stored in a name-value pairs field in scripts using the name.
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/australia/platform-administration/name-value-pair-scripting.html
release: australia
topic_type: reference
last_updated: "2026-11-06"
reading_time_minutes: 1
breadcrumb: [Reference, Field administration, Forms, fields, and lists, Configure core features, Administer the ServiceNow AI Platform]
---
# Name-value pairs field type
You can access the values stored in a name-value pairs field in scripts using the name.
## Sample script
The following example demonstrates how to add mappings to a name-value pairs field, and how to query existing values using the name.
```
// Script example demonstrating setting and getting values
var gr = new GlideRecord('u_nv_table');
gr.initialize();
gr.nv_field.name1 = "value1"; //add a name-value Pair mapping with the name "name1" and value "value1"
gr.nv_field.name2 = "value2"; //add another name-value Pair mapping with the name "name2" and value "value2"
// Access by dot notation
gs.print("name1 = " + gr.nv_field.name1); // Expected output: name1 = value1
// Iterate over each property and print name and value
for(var name in gr.nv_field) {
gs.print(name + " = " + gr.nv_field[name]);
}
gs.print(gr.nv_field); // Expected output: {"name1":"value1","name2":"value2"}
```
| title | Name-value pairs field type |
| description | You can access the values stored in a name-value pairs field in scripts using the name. |
| locale | en-US |
| canonical_url | https://www.servicenow.com/docs/r/australia/platform-administration/name-value-pair-scripting.html |
| release | australia |
| topic_type | reference |
| last_updated | 2026-11-06 |
| reading_time_minutes | 1 |
| breadcrumb | ReferenceField administrationFormsfieldsand listsConfigure core featuresAdminister the ServiceNow AI Platform |