How can I dynamically set the name of both the name and value for the field type name-value pair?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 11:14 AM
I have a field of the Name-Value pair and I need to dynamically set both the name and the value.
I tried this:
var gr = new GlideRecord('custom_table');
gr.get(sys_id);
var dynamic_name = 'Name that changes';
var dynamic_value = 'Value that changes'
gr.name_value_pair_field[dynamic_name] = dynamic_value;
gr.update
In doing so I get an error that looks like this:
'Cannot set property "Value that changes" of undefined to "Value that changes"
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 09:20 PM
The value is a stringified JSON object.
Client side this will set it and you can code in the values
g_form.setValue("u_name_value_pair",JSON.stringify({"na":"val"}));
Server side this will set it and you can code in the values
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.setValue("u_name_value_pair", JSON.stringify({"dynamicname":"dynamicvalue"}));
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2020 09:38 PM
I believe the above script would work if you make the following change:
gr.name_value_pair_field[dynamic_name] = dynamic_value.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2021 10:03 AM
I noticed that the code above is missing the parentheses after update. Should be gr.update(). gr.update will fail silently.