how to find if a script contains sub string

learnSN
Tera Expert

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

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Not sure what you exactly mean. Can you give an example?

Something like below might work.

if(your_string.indexOf(other_string) != -1) {
    ...
}

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

hi expert! 

How to check if a string contains sub string  

@naresh 

if you are referring to searching for substring in some field of your table when you are doing GlideRecord then it should be like this

var gr = new GlideRecord('incident');

gr.addQuery('short_description', 'CONTAINS', 'test');

gr.query();

var count = gr.getRowCount();

gs.info(count);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

if i would say according to the recommendations using GlideRecord and alerts function in the client script is not best practices, so if it in case any client record contains both the above(gliderecord and alerts function)records it should show the like violation on custom UI Page(named it as 'show violation in my update set') table in that that case we consider gliderecord is one sub string and alert function is another sub string.we call them from separate 'upate set best practice' table.

so my question is how to write a script(in script include)  to show them in violation table with their respective information.