Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

asifnoor
Kilo Patron

Hello,

In this article, I will show you how you can take the field columns and its values dynamiclay as key/value pairs. 

Here i am using incident table record.

var gr = new GlideRecord("incident");
if(gr.get("57af7aec73d423002728660c4cf6a71c")) {
var arr =[];
var obj;
  //this gives us all the column names and its value as key map
  for(key in gr) {
    obj={};
    obj["'"+key+"'"] = gr[key];
    arr.push(obj);
  }
}
//Now you can send this variable arr to any 3rd party and they can parse it with below code.
for(i=0;i<arr.length;i++) {
    for(key in arr[i])
    gs.print(key+" "+arr[i][key]);
}

Here is the output.

find_real_file.png

Hope this helps.

Let me know if you have any questions in the comments below.

Mark the article as helpful and bookmark if you found it useful.

 

Comments
yoli1
Tera Contributor

Hi @asifnoor how can i match the data from the API to my existing entries in the key-value table cmdb_key_value

Thanks!

Version history
Last update:
‎06-18-2022 09:03 AM
Updated by: