how to find if a script contains sub string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2020 11:54 PM
if we have two sub strings in string (GlideRecord ,Alert), how check the two sub strings
please write a program to check whether a string contains sub string
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 06:10 AM
Hi,
so you want to check
1) if client script contains alert or GlideRecord and add to your custom table with the type and the name of the script which contains that
try this sample script include functions which you can call
GlideRecord checking
checkClientScriptForGlideRecord: function(){
var rec = new GlideRecord('sys_script_client');
rec.addEncodedQuery('sys_class_name=sys_script_client^scriptLIKEnew GlideRecord(');
rec.query();
while(rec.next()){
var customRec = new GlideRecord('your custom table');
customRec.initialize();
customRec.u_type = 'Client Script';
customRec.u_substring = 'GlideRecord(';
customRec.u_name = rec.name;
customRec.insert();
}
},
Alert checking
checkClientScriptForGlideRecord: function(){
var rec = new GlideRecord('sys_script_client');
rec.addEncodedQuery('sys_class_name=sys_script_client^scriptLIKEalert(');
rec.query();
while(rec.next()){
var customRec = new GlideRecord('your custom table');
customRec.initialize();
customRec.u_type = 'Client Script';
customRec.u_substring = 'alert(';
customRec.u_name = rec.name;
customRec.insert();
}
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 06:47 AM
Hello there!
i have tried this with script include ,result is it is showing the violations with their respective sys_id also but here is the problem is alerts function table have different description and recommendation and GlideRecord have different too but both records contains GlideRecord description and recommendation.
please find the attachment so that you can
> first sys id contains alerts function
> last two sys id's contains Gliderecords
NOTE: please make sure code should be in dynamic way
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 07:50 AM
Hi Naresh,
I believe the script which was required as per your question has been shared.
You will have to enhance it as per your requirement.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 09:05 PM
Hi Naresh,
Any update on this thread?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 01:01 AM
Not sure of the question.
Following code will find all records in Alerts table (em_event) that has a particular string.
var stringToSearch = '<string to search>';
var grAlert = new GlideRecord('em_event');
grAlert.addEncodedQuery('<query string>');
grAlert.query();
while (grAlert.next()) {
gs.info(grAlert.sys_id);
}
Query string can be obtained by opening Alert table and setting filter conditions and running it. Right click on the filter breadcrumb and select "Copy query". Paste the query to the script above. "contains" filter can be used to find occurrence of a string in field.