The CreatorCon Call for Content is officially open! Get started here.

Querying Name-Value pair field to update just 1 pair

sandeep3791
Tera Contributor

Hi,

I am storing object specific characteristics in the Name-Value pair field dynamically in ServiceNow table. One record may ave 2 Chars, another may have 5 Chars.

In case of update call from external system, if it is sending us only the updated characteristic from the available 5 for example, how do we query and find out the one that needs to be updated?

E.g. Record ObjectA has one NV pair field which has 3 NV pairs store like below,

Speed  10MBPS

TrafficClass  T1

ContractTerm  36M

Now external system is sending the update call with updated characteristic Speed == 20 MBPS.

Kindly suggest how do I handle this scenario? how can I query NV pair to update just one.

Gone through - 

https://docs.servicenow.com/bundle/kingston-platform-administration/page/administer/field-administration/reference/name-value-pair-scripting.html

Thanks,

 

 

 

1 ACCEPTED SOLUTION

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

In GlideRecord you can just update the value, by passing the name and value on the element.

If it exits, the value will update, if not, the name value pair is added.

 

var gr = new GlideRecord('incident');
if (gr.get('b9a633db4f1a930035e0fdb28110c728')) {
    gr.u_name_values["speed"]= 2;
    gr.update()
}


//wrapped inside a function
function updateNameValue(table, field, sysId, propertie, value){
  var gr = new GlideRecord(table);
  if (gr.get(sysId)) {
      gr[field][propertie]= value;
      gr.update();
  }
}

updateNameValue("incident","u_name_values","b9a633db4f1a930035e0fdb28110c728",
              "speeds", "sspeed", 2);

View solution in original post

1 REPLY 1

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

In GlideRecord you can just update the value, by passing the name and value on the element.

If it exits, the value will update, if not, the name value pair is added.

 

var gr = new GlideRecord('incident');
if (gr.get('b9a633db4f1a930035e0fdb28110c728')) {
    gr.u_name_values["speed"]= 2;
    gr.update()
}


//wrapped inside a function
function updateNameValue(table, field, sysId, propertie, value){
  var gr = new GlideRecord(table);
  if (gr.get(sysId)) {
      gr[field][propertie]= value;
      gr.update();
  }
}

updateNameValue("incident","u_name_values","b9a633db4f1a930035e0fdb28110c728",
              "speeds", "sspeed", 2);