Get system properties from categories and use the properties in script

Linda Kendrick
Kilo Guru

Is is possible call a specific system properties category and then loop through the system properties to add an array list?

1 ACCEPTED SOLUTION

andrew_venables
ServiceNow Employee
ServiceNow Employee

I think you want something like this, but no idea why:



var arr = [];


var m2m = new GlideRecord('sys_properties_category_m2m');


m2m.addQuery('category.name', 'NAME_OF_CATEGORY');


m2m.query();


while (m2m.next()) {


arr.push(m2m.property.name);


}




View solution in original post

6 REPLIES 6

vibhor_dwivedi
Mega Expert

Yes . It is possible to store categories as comma separated value in a new property.



Create a new property.


Store categories in property value as comma separated.


Write a script include or UI script which will return the list of Categories as array.


Use the array where ever required.


Linda Kendrick
Kilo Guru

This is what I ended up using.



//Missing files during download


  if ((email.subject.indexOf("Matches this subject") > -1))


  {


  var arr1 = [];


  var m2m = new GlideRecord('sys_properties_category_m2m');


  m2m.addQuery('category.name', 'ReplacewithCATEGORYNAME');


  m2m.query();


  while (m2m.next()) {


  arr1.push(m2m.property.value);}



  gs.log('checking array for values:');


  for(var i=0,len=arr1.length;i!=len;i++) {


  gs.log('sys prop from array: ' + arr1[i]); }



  current.watch_list.setValue(arr1.join());



  current.assignment_group.setDisplayValue('ReplacewithAssignmentGroup');


  current.category = "network";


  current.subcategory = "Auto-alert";


  }