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.

How to add key as label for each value

Sai_reddy
Tera Contributor

Hi All,

 

I want to below highlighted red colour from the each . Could you please help me how to add it. 

 

var string="Terminations for the following employees have been processed today Rock, Joseph|157890   |Dell  |rockj@gmail.com|Tampa|Customer Support|USA|06/06/2024|Jun 12, 2024 9:20:20 AM Terminations for the following employees have been processed today Rose, Julie|045678   |RE|roseJ@gmail.com|GU|Customer Support|(None)|06/10/2024|Jun 12, 2024 8:38:07 AM​​​​​​​​​​​​​​​​​";
 
 
var fstring=string.trim().split('Terminations for the following employees have been processed today').join('|');
gs.print("fstring"+fstring);
var fields=fstring.split('|');
var users = [];
var obj = {};
//var items = fields.split(/|/);
 
 
for (var i=0;i<fields.length;i++) {
obj[fields[i]] = fields[i].toString();
users.push(obj);
 
}
gs.print(JSON.stringify(users));
0 REPLIES 0