<?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 define if condition with &amp;quot;contains&amp;quot; in Virtual Agent forum</title>
    <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965012#M8826</link>
    <description>&lt;P&gt;Hi All&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement where i need to present the submission of the catalog form.&lt;/P&gt;&lt;P&gt;i did write the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function onSubmit() {&lt;BR /&gt;var sn=g_form.getValue('service');&lt;BR /&gt;var cbox1 = g_form.getValue('did_you_read_kb_document_kb0007347_please_refer_description_for_the_link_to_kb');&lt;BR /&gt;var cbox2 = g_form.getValue('do_you_agree_with_the_automatic_expiration_policy_of_the_license_mentioned_in_kb0007347');&lt;BR /&gt;if(sn== '155936831b268a908d8ddc6fe54bcb8b')&lt;BR /&gt;{&lt;BR /&gt;if(cbox1 !== 'true' || cbox2 !== 'true')&lt;BR /&gt;{&lt;BR /&gt;alert('Select both checkboxes to submit the form.');&lt;BR /&gt;return false;&lt;BR /&gt;}&lt;BR /&gt;return true;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But its preventing only when there is "155936831b268a908d8ddc6fe54bcb8b" but the sys id "155936831b268a908d8ddc6fe54bcb8b" can be with any values.&lt;/P&gt;&lt;P&gt;Here the sys id belongs to "Copilot for M365"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phr_0-1718619555271.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/365401i6C1EBA78F4C80F62/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="phr_0-1718619555271.png" alt="phr_0-1718619555271.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But copilot for M365 can have many values along with it.&lt;/P&gt;&lt;P&gt;Example: for the values below i am still able to submit.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phr_1-1718619594341.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/365402i5D00A2AA8278C79B/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="phr_1-1718619594341.png" alt="phr_1-1718619594341.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jun 2024 10:20:20 GMT</pubDate>
    <dc:creator>phr</dc:creator>
    <dc:date>2024-06-17T10:20:20Z</dc:date>
    <item>
      <title>How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965012#M8826</link>
      <description>&lt;P&gt;Hi All&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement where i need to present the submission of the catalog form.&lt;/P&gt;&lt;P&gt;i did write the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function onSubmit() {&lt;BR /&gt;var sn=g_form.getValue('service');&lt;BR /&gt;var cbox1 = g_form.getValue('did_you_read_kb_document_kb0007347_please_refer_description_for_the_link_to_kb');&lt;BR /&gt;var cbox2 = g_form.getValue('do_you_agree_with_the_automatic_expiration_policy_of_the_license_mentioned_in_kb0007347');&lt;BR /&gt;if(sn== '155936831b268a908d8ddc6fe54bcb8b')&lt;BR /&gt;{&lt;BR /&gt;if(cbox1 !== 'true' || cbox2 !== 'true')&lt;BR /&gt;{&lt;BR /&gt;alert('Select both checkboxes to submit the form.');&lt;BR /&gt;return false;&lt;BR /&gt;}&lt;BR /&gt;return true;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But its preventing only when there is "155936831b268a908d8ddc6fe54bcb8b" but the sys id "155936831b268a908d8ddc6fe54bcb8b" can be with any values.&lt;/P&gt;&lt;P&gt;Here the sys id belongs to "Copilot for M365"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phr_0-1718619555271.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/365401i6C1EBA78F4C80F62/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="phr_0-1718619555271.png" alt="phr_0-1718619555271.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But copilot for M365 can have many values along with it.&lt;/P&gt;&lt;P&gt;Example: for the values below i am still able to submit.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phr_1-1718619594341.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/365402i5D00A2AA8278C79B/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="phr_1-1718619594341.png" alt="phr_1-1718619594341.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:20:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965012#M8826</guid>
      <dc:creator>phr</dc:creator>
      <dc:date>2024-06-17T10:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965023#M8829</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/555949"&gt;@phr&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;please check below link:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-forum/if-condition/m-p/1635449" target="_blank" rel="noopener"&gt;https://www.servicenow.com/community/developer-forum/if-condition/m-p/1635449&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;Thank you, please make helpful if you accept the solution.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:25:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965023#M8829</guid>
      <dc:creator>Yashsvi</dc:creator>
      <dc:date>2024-06-17T10:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965027#M8831</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;For Service Portal script it can be done by&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sn=g_form.getDisplayValue('service'); //returns the names of the services and not sys_id
//We make all the names lowercase to be more accurate when validating
if(sn.toLowerCase().indexOf("some special name with only lowercase chars") &amp;gt; -1){

}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:28:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965027#M8831</guid>
      <dc:creator>Simon Christens</dc:creator>
      <dc:date>2024-06-17T10:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965037#M8833</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/198604"&gt;@Simon Christens&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since i need to pass only the sys id , i am not making use of the Alphabets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to achieve this for sys id?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:34:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965037#M8833</guid>
      <dc:creator>phr</dc:creator>
      <dc:date>2024-06-17T10:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965039#M8834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/723217"&gt;@Yashsvi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since i need to pass only the sys id , i am not making use of the Alphabets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of "==" i need the "Contains" to be replaced.&lt;/P&gt;&lt;P&gt;How to achieve this for sys id?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:36:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965039#M8834</guid>
      <dc:creator>phr</dc:creator>
      <dc:date>2024-06-17T10:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965097#M8836</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/555949"&gt;@phr&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please replace the below and try:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if(sn, 'IN', '155936831b268a908d8ddc6fe54bcb8b');
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Final Code will look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;function onSubmit() {
var sn=g_form.getValue('service');
var cbox1 = g_form.getValue('did_you_read_kb_document_kb0007347_please_refer_description_for_the_link_to_kb');
var cbox2 = g_form.getValue('do_you_agree_with_the_automatic_expiration_policy_of_the_license_mentioned_in_kb0007347');
if(sn, 'IN', '155936831b268a908d8ddc6fe54bcb8b');
{
if(cbox1 !== 'true' || cbox2 !== 'true')
{
alert('Select both checkboxes to submit the form.');
return false;
}
return true;
}

}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Please Mark My Response as Correct/Helpful based on Impact&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 11:36:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965097#M8836</guid>
      <dc:creator>SN_Learn</dc:creator>
      <dc:date>2024-06-17T11:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965131#M8837</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sn=g_form.getValue('service'); //returns the list if sys_ids in the field

//Check if the list contains the sys_id your are looking for
if(sn.indexOf("sys_id") &amp;gt; -1){

}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Jun 2024 12:06:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965131#M8837</guid>
      <dc:creator>Simon Christens</dc:creator>
      <dc:date>2024-06-17T12:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to define if condition with "contains"</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965154#M8839</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/555949"&gt;@phr&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about includes() function in javascript. Can you try that to see if it helps you to achieve the desired result.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.w3schools.com/jsref/jsref_includes.asp" target="_blank" rel="noopener"&gt;https://www.w3schools.com/jsref/jsref_includes.asp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please review this line of code as well :&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if(cbox1 !== 'true' || cbox2 !== 'true') : two times equal to is used instead of "!="&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Please mark helpful/correct if my response helped you.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 12:24:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-define-if-condition-with-quot-contains-quot/m-p/2965154#M8839</guid>
      <dc:creator>Anubhav24</dc:creator>
      <dc:date>2024-06-17T12:24:10Z</dc:date>
    </item>
  </channel>
</rss>

