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

@Jaspal Singh 

To the extend with the above code, I want to count no.of scripts also... but I dont want to use "getRowCount()"

I want to use glide Aggregate function...is it possible? or I just go with increment function?

due to performance issue I dont want to prefer getRowCount..

Could you please help

SaschaWildgrube
ServiceNow Employee
ServiceNow Employee

The CodeSanity app contains a set of Instance Scan checks aimed at improving source code and application quality. Developers should run them before shipping a new application version.

Checking for scripts with hard-coded sys_ids is one of them.

Vote to make it part of the platform OOTB!

https://community.servicenow.com/community?id=view_idea&sysparm_idea_id=23716958db25d514904fa9fb1396...

Or install it right away:

https://www.wildgrube.com/servicenow-codesanity