key value pair

Supriya Mane
Tera Contributor

Hi Team,

in incident table there is one fwa field of type name value pair... pls check if we can add those fwa values there with attribute name in name part and its value in value part while create/ update incident, How we can .work in script include or mapping in ServiceNow

2 REPLIES 2

Dnyaneshwaree
Mega Sage

Hello @Supriya Mane ,

Please refer below code for a example and update it as per your req:
Script include:

var FWAUtils = Class.create();
FWAUtils.prototype = {
  initialize: function() {},

  addOrUpdateFWA: function(incidentSysId, fwaData) {
    var incident = new GlideRecord('incident');
    if (incident.get(incidentSysId)) {
      var fwaField = incident.getValue('fwa_field'); // Replace 'fwa_field' with the actual field name
      var fwaObj = fwaField ? JSON.parse(fwaField) : {};

      for (var key in fwaData) {
        fwaObj[key] = fwaData[key];
      }

      incident.setValue('fwa_field', JSON.stringify(fwaObj));
      incident.update();
      return true;
    }
    return false;
  },

  type: 'FWAUtils'
};

Call it from any server side script i.e., BR, Ui action etc.

var fwaData = {
  "attribute1": "value1",
  "attribute2": "value2"
};

var fwaUtils = new FWAUtils();
fwaUtils.addOrUpdateFWA('INC0010009', fwaData); // Replace 'INC0010001' with the actual incident Sys ID


Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

How to trigger json for above