GlideAggregate and group_concat in a ServiceNow script to concatenate the values of a field called "sys_id" from multiple records grouped by the "Category" field ServiceNow
var agg = new GlideAggregate('incident'); // Replace 'tableName' with the actual table name you want to query agg.addAggregate('group_concat', 'sys_id'); agg.groupBy('category'); agg.query(); while (agg.next()) { var category = agg.getValue('category'); var concatenatedNames = agg.getAggregate('group_concat', 'sys_id'); gs.info('Category: ' + category + ', Concatenated Names: ' + concatenatedNames); }
GlideAggregate and group_concat in a ServiceNow script
Working Code Asked question July 14, 2023