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

rgm276
Mega Guru

Linda


not sure exactly what you are trying to loop through, an example might help


such as, here is a quick example of where I get the system property color to allow our CMS self-service portal to inherit the base color of the instance of service-now we are running in.   IE Prod .vs. Test , the header will have a different color for a quick visual.  


<g:evaluate>


      var bg = gs.getProperty('css.base.color');


</g:evaluate>


<script>


var div1 = document.getElementById( 'topHeaderContainer' );


div1.style.backgroundColor = "${bg}";


</script>


Here is what I am working on.


Have a system that is monitoring file statuses and will send a notification to ServiceNow when something goes wrong. Have it currently setup in the inbound email action to create an incident ticket and set the assignment group to the Network Team when these alerts emails are received.


What is happening is other users in the ABC department don't know the ticket has been created so then they call the users in the Network Team to check on it. Creating a lot of extra work for the teams to follow up. The requirement I have is to add specific users from the ABC Department automatically to the watch list. Knowing the users will change over time, thought using a System Property Category for each of the types of alerts (Error File Upload, Missing File Download, Missing File Upload) . Each of the users would have their own system property and then I could add their property to which System Property Category Alert they needed to be added to the watch list. I have 4 users to add to the alerts but not all 4 users are part of each alert.


If User4 now needs to be part of Error File Upload then can just add the user system property to the category and not have to change the inbound email action. Trying to keep the inbound email action 'dumb'.



Error File Upload


        User1, User2, User3


Missing File Download


        User2, User3, User4


Missing File Upload


        User1, User2, User4


justin_drysdale
Mega Guru

You can add system specific properties to an array.     Here I've added any system property starting with, 'com.snc' to an array:


var sys_prop_arr = [];


var sys_props = new GlideRecord('sys_properties');


      sys_props.addQuery('nameSTARTSWITHcom.snc');


      sys_props.query();


      while(sys_props.next()) {


          //gs.print('Adding Property to array: ' + sys_props.name);


          sys_prop_arr.push(sys_props.name + '');


      }


   


   


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


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


gs.print('sys prop from array: ' + sys_prop_arr[i]);


}



I ran this as a background script.


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);


}