<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question how to find if a script contains sub string in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587900#M159679</link>
    <description>&lt;P&gt;if we have two&amp;nbsp; sub strings in string (GlideRecord ,Alert), how check the two sub strings&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please write a program to check whether a string contains sub string&lt;/P&gt;</description>
    <pubDate>Sun, 29 Nov 2020 07:54:32 GMT</pubDate>
    <dc:creator>learnSN</dc:creator>
    <dc:date>2020-11-29T07:54:32Z</dc:date>
    <item>
      <title>how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587900#M159679</link>
      <description>&lt;P&gt;if we have two&amp;nbsp; sub strings in string (GlideRecord ,Alert), how check the two sub strings&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please write a program to check whether a string contains sub string&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 07:54:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587900#M159679</guid>
      <dc:creator>learnSN</dc:creator>
      <dc:date>2020-11-29T07:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587901#M159680</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Not sure what you exactly mean. Can you give an example?&lt;/P&gt;
&lt;P&gt;Something like below might work.&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if(your_string.indexOf(other_string) != -1) {
    ...
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If my answer helped you in any way, please then mark it as helpful.&lt;/P&gt;
&lt;P class="ng-scope"&gt;Kind regards,&lt;BR /&gt;Mark&lt;BR /&gt;&lt;EM&gt;&lt;A href="https://community.servicenow.com/community?id=community_blog&amp;amp;sys_id=fb488720dbaacc504819fb2439961900" target="_blank" rel="noopener noreferrer nofollow"&gt;2020 ServiceNow Community MVP&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;A href="https://developer.servicenow.com/blog.do?p=/post/all-stars/" target="_blank" rel="noopener noreferrer nofollow"&gt;2020 ServiceNow Developer MVP&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;---&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;A href="https://www.linkedin.com/in/markroethof/" target="_blank" rel="noopener noreferrer nofollow"&gt;LinkedIn&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.servicenow.com/community?id=community_blog&amp;amp;sys_id=14e51965db2200d013b5fb24399619fb" target="_blank" rel="noopener noreferrer nofollow"&gt;Community article list&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 08:30:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587901#M159680</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2020-11-29T08:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587902#M159681</link>
      <description>&lt;P&gt;Not sure of the question.&lt;/P&gt;
&lt;P&gt;Following code will find all records in Alerts table (em_event) that has a particular string.&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var stringToSearch = '&amp;lt;string to search&amp;gt;';

var grAlert = new GlideRecord('em_event');
grAlert.addEncodedQuery('&amp;lt;query string&amp;gt;');
grAlert.query();
while (grAlert.next()) {
  gs.info(grAlert.sys_id);
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/36806i28C602C5FF38905C/image-size/large?v=v2&amp;amp;px=999" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 09:01:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587902#M159681</guid>
      <dc:creator>Hitoshi Ozawa</dc:creator>
      <dc:date>2020-11-29T09:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587903#M159682</link>
      <description>&lt;P&gt;hi expert!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to check if a string contains sub string&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 13:29:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587903#M159682</guid>
      <dc:creator>learnSN</dc:creator>
      <dc:date>2020-11-29T13:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587904#M159683</link>
      <description>&lt;P&gt;&lt;SN-MENTION class="sn-mention" table="live_profile" sysid="12749614dbd73f8013b5fb2439961904"&gt;@naresh&lt;/SN-MENTION&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;P&gt;var gr = new GlideRecord('incident');&lt;/P&gt;
&lt;P&gt;gr.addQuery('short_description', 'CONTAINS', 'test');&lt;/P&gt;
&lt;P&gt;gr.query();&lt;/P&gt;
&lt;P&gt;var count = gr.getRowCount();&lt;/P&gt;
&lt;P&gt;gs.info(count);&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 13:38:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587904#M159683</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-29T13:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587905#M159684</link>
      <description>&lt;P&gt;Hello Ankur,&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;so my question is how to write a script(in script include)&amp;nbsp; to show them in violation table with their respective information.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 14:03:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587905#M159684</guid>
      <dc:creator>learnSN</dc:creator>
      <dc:date>2020-11-29T14:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587906#M159685</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;so you want to check&lt;/P&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;P&gt;try this sample script include functions which you can call&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;GlideRecord checking&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;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();

}

},

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alert checking&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;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();

}

},&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 14:10:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587906#M159685</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-29T14:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587907#M159686</link>
      <description>&lt;P&gt;Hello there!&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;description and recommendation.&lt;/P&gt;
&lt;P&gt;please find the attachment so that you can&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt; first sys id contains alerts function&lt;/P&gt;
&lt;P&gt;&amp;gt; last two&amp;nbsp; sys id's contains Gliderecords&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: please make sure code should be in dynamic way&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 14:47:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587907#M159686</guid>
      <dc:creator>learnSN</dc:creator>
      <dc:date>2020-11-29T14:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587908#M159687</link>
      <description>&lt;P&gt;Hi Naresh,&lt;/P&gt;
&lt;P&gt;I believe the script which was required as per your question has been shared.&lt;/P&gt;
&lt;P&gt;You will have to enhance it as per your requirement.&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 15:50:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587908#M159687</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-29T15:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a script contains sub string</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587909#M159688</link>
      <description>&lt;P&gt;Hi Naresh,&lt;/P&gt;
&lt;P&gt;Any update on this thread?&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 05:05:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-find-if-a-script-contains-sub-string/m-p/587909#M159688</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-11-30T05:05:49Z</dc:date>
    </item>
  </channel>
</rss>

