<?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 compare reference fields in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2984665#M397</link>
    <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;function&lt;/SPAN&gt;&lt;SPAN&gt; onChange(control, oldValue, newValue, isLoading) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (isLoading || newValue == &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; lm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'line_manager'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; dm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'director_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; gm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'general_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt;(lm.employee_number == dm.employee_number || lm.employee_number==gm.employee_number || dm.employee_number==gm.employee_number){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;alert(&lt;/SPAN&gt;&lt;SPAN&gt;"hi"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'line_manager'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'director_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'general_approvals'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I tried this showing as javascript error.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I have 3 reference fields on the form where user selects managers&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;so the managers are to be unique and if it same then it gives an alert and clears the value&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/279914"&gt;@Rupanjani&lt;/a&gt;&amp;nbsp;can you help here&lt;/P&gt;&lt;P&gt;Thanks advance&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2024 10:51:37 GMT</pubDate>
    <dc:creator>pk2184046</dc:creator>
    <dc:date>2024-07-09T10:51:37Z</dc:date>
    <item>
      <title>how to compare reference fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2984665#M397</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;function&lt;/SPAN&gt;&lt;SPAN&gt; onChange(control, oldValue, newValue, isLoading) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (isLoading || newValue == &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; lm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'line_manager'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; dm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'director_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; gm=g_form.getReference(&lt;/SPAN&gt;&lt;SPAN&gt;'general_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt;(lm.employee_number == dm.employee_number || lm.employee_number==gm.employee_number || dm.employee_number==gm.employee_number){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;alert(&lt;/SPAN&gt;&lt;SPAN&gt;"hi"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'line_manager'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'director_approval'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; g_form.clearValue(&lt;/SPAN&gt;&lt;SPAN&gt;'general_approvals'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I tried this showing as javascript error.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I have 3 reference fields on the form where user selects managers&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;so the managers are to be unique and if it same then it gives an alert and clears the value&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/279914"&gt;@Rupanjani&lt;/a&gt;&amp;nbsp;can you help here&lt;/P&gt;&lt;P&gt;Thanks advance&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 10:51:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2984665#M397</guid>
      <dc:creator>pk2184046</dc:creator>
      <dc:date>2024-07-09T10:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare reference fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2984695#M399</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/581682"&gt;@pk2184046&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can check with g_form.getValue() instead of getReference().&lt;/P&gt;&lt;P&gt;For reference fields, getValue will be returned as the sys_id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try below script and check.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
   
return;
   }

   var lm=g_form.getValue('line_manager');
   var dm=g_form.getValue('director_approval');
   var gm=g_form.getValue('general_approval');

   if(lm == dm || lm == gm || dm == gm){
   alert("hi");
   g_form.addErrorMessage('Line Manager, Director Approval and General Approval needs to be different.)
   g_form.clearValue('line_manager');
   g_form.clearValue('director_approval');
   g_form.clearValue('general_approvals');
   }
   
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 11:13:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2984695#M399</guid>
      <dc:creator>Rupanjani</dc:creator>
      <dc:date>2024-07-09T11:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare reference fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2987781#M406</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/581682"&gt;@pk2184046&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try above code can clear all the values if one is matched.&lt;BR /&gt;You need to write onChange client script on every field&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;onChange Client script when line manager is set/changed&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var lm=g_form.getValue('line_manager');
   var dm=g_form.getValue('director_approval');
   var gm=g_form.getValue('general_approval');

if(dm != '' &amp;amp;&amp;amp; gm != ''){   
   if(lm == dm){
       g_form.clearValue('line_manager');
       g_form.showFieldMsg('line_manager', 'Line Manager and Director approver can not be same', 'error');
   } else if (lm == gm) {
       g_form.clearValue('line_manager');
       g_form.showFieldMsg('line_manager', 'Line Manager and General approver can not be same', 'error');
   } 
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;onChange client script when Director approver is set/changed&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
return;
   }

   var lm=g_form.getValue('line_manager');
   var dm=g_form.getValue('director_approval');
   var gm=g_form.getValue('general_approval');

if(lm != '' &amp;amp;&amp;amp; gm != ''){   
   if(dm == lm){
       g_form.clearValue('director_approval');
       g_form.showFieldMsg('director_approval', 'Director approver and Line Manager can not be same', 'error');
   } else if (dm == gm) {
       g_form.clearValue('director_approval');
       g_form.showFieldMsg('director_approval', 'Director approver and General approver can not be same', 'error');
   } 
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;onChange client script when general approver is set/changed.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var lm=g_form.getValue('line_manager');
   var dm=g_form.getValue('director_approval');
   var gm=g_form.getValue('general_approval');

if(lm != '' &amp;amp;&amp;amp; dm != ''){   
   if(gm == lm){
       g_form.clearValue('general_approval');
       g_form.showFieldMsg('general_approval', 'General Approver and Line Manager can not be same', 'error');
   } else if (gm == dm) {
       g_form.clearValue('general_approval');
       g_form.showFieldMsg('general_approval', 'General Approver and Director approver can not be same', 'error');
   } 
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modify the error messages as required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 17:50:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2987781#M406</guid>
      <dc:creator>Rupanjani</dc:creator>
      <dc:date>2024-07-11T17:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare reference fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2989671#M413</link>
      <description>&lt;P&gt;Hi Rupa,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response.&lt;/P&gt;&lt;P&gt;Small modifications to the script it worked.&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 06:30:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-compare-reference-fields/m-p/2989671#M413</guid>
      <dc:creator>pk2184046</dc:creator>
      <dc:date>2024-07-15T06:30:21Z</dc:date>
    </item>
  </channel>
</rss>

