<?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 Re: Custom Assignment Rule Script in SecOps forum</title>
    <link>https://www.servicenow.com/community/secops-forum/custom-assignment-rule-script/m-p/3195872#M12490</link>
    <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/866360"&gt;@browne26&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your script looks like fine, but there are a couple of areas that could lead to unexpected behavior, especially when you're checking for the u_event_group value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var gr = new GlideRecord('server');
var ciSID = current.sys_id;

gr.addQuery('sys_id', ciSID);
gr.query();

if (gr.getRowCount() &amp;gt; 0) {
    gr.next();  // Make sure we're processing the first record
    var eventGroup = gr.getValue('u_event_group');

    if (eventGroup) {
        current.assignment_group = eventGroup;
    } else {
        gs.log('No event group found for CI: ' + ciSID);
        // Optionally handle case where no event group is found
    }
} else {
    gs.log('No server record found for CI: ' + ciSID);
    // Optionally handle the case where no server record is found
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Added getRowCount() to check for multiple records and ensure you're only processing one.&lt;/LI&gt;&lt;LI&gt;Simplified the check for an empty eventGroup by just using if (eventGroup).&lt;/LI&gt;&lt;LI&gt;Added gs.log calls to provide visibility into the script's behavior.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 20:40:01 GMT</pubDate>
    <dc:creator>Medi C</dc:creator>
    <dc:date>2025-03-04T20:40:01Z</dc:date>
    <item>
      <title>Custom Assignment Rule Script</title>
      <link>https://www.servicenow.com/community/secops-forum/custom-assignment-rule-script/m-p/3195867#M12489</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to troubleshoot a custom script that should be assigning VITs to the group in the variable u_event_group. This script is assigning records that do not have this custom dictionary entry and/or the dictionary entry is empty. If anyone could review this script and identify potential bugs, I would greatly appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;gr&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;GlideRecord&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'server'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;ciSID&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;current&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;sys_id&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;gr&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;addQuery&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'sys_id'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;ciSID&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN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AN&gt;&lt;SPAN&gt;current&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;assignment_group&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;eventGroup&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;else&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;// No group found&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;SPAN&gt;else&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;// No group found&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 04 Mar 2025 20:33:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/secops-forum/custom-assignment-rule-script/m-p/3195867#M12489</guid>
      <dc:creator>browne26</dc:creator>
      <dc:date>2025-03-04T20:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Assignment Rule Script</title>
      <link>https://www.servicenow.com/community/secops-forum/custom-assignment-rule-script/m-p/3195872#M12490</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/866360"&gt;@browne26&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your script looks like fine, but there are a couple of areas that could lead to unexpected behavior, especially when you're checking for the u_event_group value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var gr = new GlideRecord('server');
var ciSID = current.sys_id;

gr.addQuery('sys_id', ciSID);
gr.query();

if (gr.getRowCount() &amp;gt; 0) {
    gr.next();  // Make sure we're processing the first record
    var eventGroup = gr.getValue('u_event_group');

    if (eventGroup) {
        current.assignment_group = eventGroup;
    } else {
        gs.log('No event group found for CI: ' + ciSID);
        // Optionally handle case where no event group is found
    }
} else {
    gs.log('No server record found for CI: ' + ciSID);
    // Optionally handle the case where no server record is found
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Added getRowCount() to check for multiple records and ensure you're only processing one.&lt;/LI&gt;&lt;LI&gt;Simplified the check for an empty eventGroup by just using if (eventGroup).&lt;/LI&gt;&lt;LI&gt;Added gs.log calls to provide visibility into the script's behavior.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 20:40:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/secops-forum/custom-assignment-rule-script/m-p/3195872#M12490</guid>
      <dc:creator>Medi C</dc:creator>
      <dc:date>2025-03-04T20:40:01Z</dc:date>
    </item>
  </channel>
</rss>

