<?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: Script not working as expected in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463107#M5777</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175" target="_blank" rel="noopener"&gt;@pardhiv&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&amp;nbsp;I can see that there is some logic&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;issues in the code&lt;/STRONG&gt;, which may cause the mismatching in count&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First One:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;You are using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;two&amp;nbsp;grCrel.next() function&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;along with if and while here&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; " if (&lt;STRONG&gt;!grCrel.next&lt;/STRONG&gt;()) { ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while (&lt;STRONG&gt;grCrel.next&lt;/STRONG&gt;()) {&lt;STRONG&gt;"&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;which is wrong because consider below scenarios&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario 1: &lt;/STRONG&gt;When&amp;nbsp;Server has NO relations, it will work fine&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Step&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; What happens &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;grCrel.next()&lt;/TD&gt;&lt;TD&gt;returns FALSE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IF block&lt;/TD&gt;&lt;TD&gt;runs → push server&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;while(grCrel.next())&lt;/TD&gt;&lt;TD&gt;returns FALSE → loop skipped&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;BUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario 2:&lt;/STRONG&gt;Server HAS relations (example: 2 relations) Rel1, Rel2&lt;/P&gt;&lt;P&gt;IFCondition: !grCrel.next()here our rel1 is checked and cursor is moved to rel2.&lt;/P&gt;&lt;P&gt;while(grCrel.next())&amp;nbsp;here in the while loop rel2 is checked,&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;so rel1 will always be skipped&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;Second One:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/FONT&gt;You are pushing server inside the loop which is causing the duplicates&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;in this code portion:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;while&lt;/STRONG&gt;(..){&lt;/P&gt;&lt;P&gt;{if (!grDrel.next())&lt;/P&gt;&lt;P&gt;{ unMapdServer.push(grSer2.sys_id.toString()); }}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Consider&lt;/STRONG&gt;: If server 1 has 3 discovered service, none of these services are linked to business application means the same server will be pushed 3 times in the array&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the corrected code is...&lt;/P&gt;&lt;PRE&gt;unMappedSrvr: function() {

    var unMapdServer = [];
    var inScopeQuery = gs.getProperty('inscope.server.app.mapping'); 
    var grSer2 = new GlideRecord('cmdb_ci_server');

    grSer2.addEncodedQuery('install_status=1^environment=Production^operational_status=1');
    grSer2.query();

    while (grSer2.next()) {

        var isUnmapped = false;

        var grCrel = new GlideRecord('cmdb_rel_ci');
        grCrel.addQuery('child', grSer2.sys_id);
        grCrel.addQuery('parent.sys_class_name', 'INSTANCEOF', 'cmdb_ci_service_discovered');
        grCrel.query();

        // 1 If NO discovered service relation
        if (!grCrel.hasNext()) {
            isUnmapped = true;
        }

        // 2 If discovered services exist, check business app mapping
        while (!isUnmapped &amp;amp;&amp;amp; grCrel.next()) {

            var grDrel = new GlideRecord('cmdb_rel_ci');
            grDrel.addQuery('child', grCrel.parent);
            grDrel.addQuery('parent.sys_class_name', 'cmdb_ci_business_app');
            grDrel.query();

            // If service NOT linked to business app
            if (!grDrel.hasNext()) {
                isUnmapped = true;
                break; // stop checking further services
            }
        }

        // 3 Push only once
        if (isUnmapped) {
            unMapdServer.push(grSer2.sys_id.toString());
        }
    }

    return unMapdServer.join(',');
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Fix I applied&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;hasNext()&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;==&amp;gt; if (!grCrel.hasNext()) { ... } -&amp;gt; only checks if record exists, will not move the cursor to next record.&lt;/P&gt;&lt;P&gt;2)&lt;STRONG&gt;Handled duplicates ==&amp;gt;&amp;nbsp;&lt;/STRONG&gt;I avoided pushing the server inside the loop. Instead, I used a flag to mark the server as unmapped and immediately broke out of the loop when the condition was met. After exiting the loop, I pushed the server only once, which prevents duplicate entries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;I have made lot of efforts for this , if you find these useful please mark it as helpful and please accept my solution...&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;Best Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;SIVASANKARI S&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;ITOM Engineer&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jan 2026 08:52:56 GMT</pubDate>
    <dc:creator>sivasankaris</dc:creator>
    <dc:date>2026-01-08T08:52:56Z</dc:date>
    <item>
      <title>Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462889#M5773</link>
      <description>&lt;P&gt;I am trying to create 3 reports,&lt;BR /&gt;1. To show servers that are in scope (Operational status = operation AND install status = installed, Environment=Production) (Count 1424)&lt;/P&gt;&lt;P&gt;2. Servers that are &lt;STRONG&gt;in scope&lt;/STRONG&gt; mapped to a application , (used sysId is one of and called a Script include) - 559 seems realistic&lt;/P&gt;&lt;P&gt;3. Servers that are &lt;STRONG&gt;in Scope&lt;/STRONG&gt; and not mapped to a application (used sysId is one of and called a Script include) -Number is more than servers that are in Scope&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;unMappedSrvr: function() {

        var unMapdServer = [];
        var inScopeQuery = gs.getProperty('inscope.server.app.mapping');// Used same property for Mapped servers too
        var grSer2 = new GlideRecord('cmdb_ci_server');
        //grSer2.addEncodedQuery(inScopeQuery ); //Seems like this failing , return count shows more thanCIs as per below scope , returns 9000~
        grSer2.addEncodedQuery('install_status=1^environment=Production^operational_status=1'); //This is same filter as property, count is within scope, returns 751
        grSer2.query();
        while (grSer2.next()) {
            var grCrel = new GlideRecord('cmdb_rel_ci');
            grCrel.addQuery('child', grSer2.sys_id);
            grCrel.addQuery('parent.sys_class_name', 'INSTANCEOF', 'cmdb_ci_service_discovered');
            grCrel.query();
            if (!grCrel.next()) {
                unMapdServer.push(grSer2.sys_id.toString());
            }
            while (grCrel.next()) {
                var grDrel = new GlideRecord('cmdb_rel_ci');
                grDrel.addQuery('child', grCrel.parent);
                grDrel.addQuery('parent.sys_class_name', 'cmdb_ci_business_app');
                grDrel.query();
                if (!grDrel.next()) {
                    unMapdServer.push(grSer2.sys_id.toString());
                }
            }
        }
        return unMapdServer.join(',');
    },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pardhiv_0-1767848029986.png" style="width: 729px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/494554iD850963AF80EA49E/image-dimensions/729x133?v=v2" width="729" height="133" role="button" title="pardhiv_0-1767848029986.png" alt="pardhiv_0-1767848029986.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pardhiv_1-1767848101035.png" style="width: 669px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/494555i80C1228C9DED0FE0/image-dimensions/669x239?v=v2" width="669" height="239" role="button" title="pardhiv_1-1767848101035.png" alt="pardhiv_1-1767848101035.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 04:56:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462889#M5773</guid>
      <dc:creator>pardhiv</dc:creator>
      <dc:date>2026-01-08T04:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462896#M5774</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175"&gt;@pardhiv&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you getting results when you call the script in the background script?if yes&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a checkbox called Sandbox Enabled on the script include table make it true and try&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Chaitanya&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 05:11:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462896#M5774</guid>
      <dc:creator>Chaitanya ILCR</dc:creator>
      <dc:date>2026-01-08T05:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462913#M5775</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175"&gt;@pardhiv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&lt;STRONG&gt;-&amp;gt; gs.getProperty() won't work in client callable script include when it's called from a reporting filter condition as it will be executed on client side.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I have faced similar challenge earlier and was surprised to know this drawback.&lt;/P&gt;
&lt;P&gt;Instead you can query &lt;STRONG&gt;sys_properties&lt;/STRONG&gt; table with that property name and get the value and then use&lt;/P&gt;
&lt;P&gt;I shared solution for this in 2022&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.servicenow.com/community/itsm-forum/client-callable-script-include-issue-as-script-filter-in-reports/m-p/561756" target="_blank" rel="noopener"&gt;Client Callable Script include issue as script filter in reports&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Before: I am using gs.getProperty() and it didn't give result&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gs getProperty in script include report filter condition not working.gif" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/494556i51D857CA62D4E700/image-size/large?v=v2&amp;amp;px=999" role="button" title="gs getProperty in script include report filter condition not working.gif" alt="gs getProperty in script include report filter condition not working.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;After: I used GlideRecord to query properties and used and it worked&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gs getProperty in script include report filter condition working with gliderecord.gif" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/494557i45D3251A6F24A1FF/image-size/large?v=v2&amp;amp;px=999" role="button" title="gs getProperty in script include report filter condition working with gliderecord.gif" alt="gs getProperty in script include report filter condition working with gliderecord.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":light_bulb:"&gt;💡&lt;/span&gt; If my response helped, please mark it as correct &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; and close the thread &lt;span class="lia-unicode-emoji" title=":locked:"&gt;🔒&lt;/span&gt;— this helps future readers find the solution faster! &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 05:51:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3462913#M5775</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-01-08T05:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463107#M5777</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175" target="_blank" rel="noopener"&gt;@pardhiv&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&amp;nbsp;I can see that there is some logic&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;issues in the code&lt;/STRONG&gt;, which may cause the mismatching in count&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First One:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;You are using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;two&amp;nbsp;grCrel.next() function&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;along with if and while here&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; " if (&lt;STRONG&gt;!grCrel.next&lt;/STRONG&gt;()) { ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while (&lt;STRONG&gt;grCrel.next&lt;/STRONG&gt;()) {&lt;STRONG&gt;"&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;which is wrong because consider below scenarios&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario 1: &lt;/STRONG&gt;When&amp;nbsp;Server has NO relations, it will work fine&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Step&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; What happens &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;grCrel.next()&lt;/TD&gt;&lt;TD&gt;returns FALSE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IF block&lt;/TD&gt;&lt;TD&gt;runs → push server&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;while(grCrel.next())&lt;/TD&gt;&lt;TD&gt;returns FALSE → loop skipped&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;BUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario 2:&lt;/STRONG&gt;Server HAS relations (example: 2 relations) Rel1, Rel2&lt;/P&gt;&lt;P&gt;IFCondition: !grCrel.next()here our rel1 is checked and cursor is moved to rel2.&lt;/P&gt;&lt;P&gt;while(grCrel.next())&amp;nbsp;here in the while loop rel2 is checked,&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;so rel1 will always be skipped&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;Second One:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/FONT&gt;You are pushing server inside the loop which is causing the duplicates&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;in this code portion:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;while&lt;/STRONG&gt;(..){&lt;/P&gt;&lt;P&gt;{if (!grDrel.next())&lt;/P&gt;&lt;P&gt;{ unMapdServer.push(grSer2.sys_id.toString()); }}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Consider&lt;/STRONG&gt;: If server 1 has 3 discovered service, none of these services are linked to business application means the same server will be pushed 3 times in the array&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the corrected code is...&lt;/P&gt;&lt;PRE&gt;unMappedSrvr: function() {

    var unMapdServer = [];
    var inScopeQuery = gs.getProperty('inscope.server.app.mapping'); 
    var grSer2 = new GlideRecord('cmdb_ci_server');

    grSer2.addEncodedQuery('install_status=1^environment=Production^operational_status=1');
    grSer2.query();

    while (grSer2.next()) {

        var isUnmapped = false;

        var grCrel = new GlideRecord('cmdb_rel_ci');
        grCrel.addQuery('child', grSer2.sys_id);
        grCrel.addQuery('parent.sys_class_name', 'INSTANCEOF', 'cmdb_ci_service_discovered');
        grCrel.query();

        // 1 If NO discovered service relation
        if (!grCrel.hasNext()) {
            isUnmapped = true;
        }

        // 2 If discovered services exist, check business app mapping
        while (!isUnmapped &amp;amp;&amp;amp; grCrel.next()) {

            var grDrel = new GlideRecord('cmdb_rel_ci');
            grDrel.addQuery('child', grCrel.parent);
            grDrel.addQuery('parent.sys_class_name', 'cmdb_ci_business_app');
            grDrel.query();

            // If service NOT linked to business app
            if (!grDrel.hasNext()) {
                isUnmapped = true;
                break; // stop checking further services
            }
        }

        // 3 Push only once
        if (isUnmapped) {
            unMapdServer.push(grSer2.sys_id.toString());
        }
    }

    return unMapdServer.join(',');
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Fix I applied&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;hasNext()&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;==&amp;gt; if (!grCrel.hasNext()) { ... } -&amp;gt; only checks if record exists, will not move the cursor to next record.&lt;/P&gt;&lt;P&gt;2)&lt;STRONG&gt;Handled duplicates ==&amp;gt;&amp;nbsp;&lt;/STRONG&gt;I avoided pushing the server inside the loop. Instead, I used a flag to mark the server as unmapped and immediately broke out of the loop when the condition was met. After exiting the loop, I pushed the server only once, which prevents duplicate entries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;I have made lot of efforts for this , if you find these useful please mark it as helpful and please accept my solution...&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;Best Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;SIVASANKARI S&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;ITOM Engineer&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 08:52:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463107#M5777</guid>
      <dc:creator>sivasankaris</dc:creator>
      <dc:date>2026-01-08T08:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463874#M5803</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175"&gt;@pardhiv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope you are doing good.&lt;/P&gt;
&lt;P&gt;Did my reply answer your question?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":light_bulb:"&gt;💡&lt;/span&gt; If my response helped, please mark it as correct &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; and close the thread &lt;span class="lia-unicode-emoji" title=":locked:"&gt;🔒&lt;/span&gt;— this helps future readers find the solution faster! &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2026 03:08:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463874#M5803</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-01-09T03:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Script not working as expected</title>
      <link>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463975#M5804</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/321175"&gt;@pardhiv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the response you marked correct is not valid as that doesn't answer your gs.getProperty() question.&lt;/P&gt;
&lt;P&gt;the solution I shared talks about workaround for gs.getProperty() as it doesn't work in script include report filter conditions.&lt;/P&gt;
&lt;P&gt;Please mark appropriate response as correct so that it helps future members.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2026 06:17:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/script-not-working-as-expected/m-p/3463975#M5804</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-01-09T06:17:29Z</dc:date>
    </item>
  </channel>
</rss>

