Is there a way to find all the scripts where sysIDs are hardcoded

Harshit
Tera Contributor

Is there a way to find all the scripts in the system where sysIDs are hardcoded.

Any response is appreciated!!

Thanks,

Harshit

1 ACCEPTED SOLUTION

Shiva Thomas
Kilo Sage

Hi Harshit,



What a nice surprise to meet you on Community!  



SNGuru solution works if you search for a specific sys_id. If you want to search for any hardcoded sys_id you can use a background script like this, using a regular expression.


var regexp = /[0-9a-f]{32}/; // Match any string made of 32 hexadecimal characters


var gr = new GlideRecord('sys_script'); // Replace this to check for other tables. This one is business rules


// gr.addQuery('sys_customer_update=true'); // Uncomment this if you want to exclude out-of-the-box scripts from ServiceNow


gr.query();


while (gr.next()) {


  if (gr.script.match(regexp))


      gs.print('Sys_id found in script: ' + gr.name);


}


I hope you are well since our last project.


View solution in original post

6 REPLIES 6

Shiva Thomas
Kilo Sage

Hi Harshit,



What a nice surprise to meet you on Community!  



SNGuru solution works if you search for a specific sys_id. If you want to search for any hardcoded sys_id you can use a background script like this, using a regular expression.


var regexp = /[0-9a-f]{32}/; // Match any string made of 32 hexadecimal characters


var gr = new GlideRecord('sys_script'); // Replace this to check for other tables. This one is business rules


// gr.addQuery('sys_customer_update=true'); // Uncomment this if you want to exclude out-of-the-box scripts from ServiceNow


gr.query();


while (gr.next()) {


  if (gr.script.match(regexp))


      gs.print('Sys_id found in script: ' + gr.name);


}


I hope you are well since our last project.


Hi Shiva,



Indeed!! Good to hear from you as always and thank you for your reply. Works like a charm



Best regards,


Harshit


@Shiva Thomas 

To the extend of the above code, I want to count no.of scripts also... without using "RowCount"

I want to glide Aggregate function