<?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: Round Robin Business Rule script Question about addQuerry order for multiple custom fields in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231742#M2701</link>
    <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when is the business rule running? on which table and what's the condition?&lt;/P&gt;
&lt;P&gt;Your business rule should be Before insert/update.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {
    // Query the assignment group to check if u_roundrobin is true
    var group = new GlideRecord('sys_user_group');
    if (group.get(current.assignment_group) &amp;amp;&amp;amp; group.u_roundrobin) {
        // Query all members of the group who are not out of office
        var gMember = new GlideRecord('sys_user_grmember');
        gMember.addQuery('group', current.assignment_group);
        gMember.addQuery('user.u_out_of_office', false);
        gMember.query();

        // If there are members available, assign the incident to the first one found
        if (gMember.next()) {
            current.assigned_to = gMember.user;
        }
    }
})(current, previous);&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Apr 2025 14:12:28 GMT</pubDate>
    <dc:creator>Ankur Bawiskar</dc:creator>
    <dc:date>2025-04-08T14:12:28Z</dc:date>
    <item>
      <title>Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231615#M2699</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attempting to build a round robin business rule script that will need to look at a couple of&amp;nbsp;a custom fields:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;u_roundrobin on the&amp;nbsp; sys_user_group table as true/false.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;"u_out_of_office" (true/false) on the sys_user table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;What I want to do with my business rule, is:&lt;BR /&gt;1) Query the current.assignment_group to see if u_roundrobin = true&lt;/P&gt;&lt;P&gt;2) If true, query all members of that group and only include those who's u_out_off_office = false&lt;BR /&gt;&lt;BR /&gt;My code so far:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function executeRule(current, previous /*null when async*/) {

var gMember = new GlideRecord('sys_user_grmember');
gMember.addQuery('group', current.assignment_group);
gs.print("assignmentGroup:"+gMember); 
gs.log("assignmentGroup:"+gMember);
var rrMember = gMember.addQuery('u_roundrobin', true);
gs.print("rrMember:"+rrMember);
gs.log("rrMember:"+rrMember);

if(rrMember == true)
{
var agroup = new GlideRecord('sys_user_grmember');
agroup.addQuery('group', current.assignment_group);
var ooo = agroup.addQuery('u_outlook_out_of_office', true);
agroup.query();
gs.print("ooo:"+ooo);
gs.log("ooo:"+ooo);
if (ooo == true){
if (gMember.next()) {
		current.assigned_to = gMember.user;
	}
}
}
})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;I'm struggling with the logic of query group to determine if u_roundrobin is true, then multiple if's or if I can do it all within a query and only reference members of the current assignment group (if it's a member of roundrobin and the user is not outofoffice (ooo).&lt;BR /&gt;&lt;BR /&gt;thoughts?&lt;BR /&gt;thank you.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 12:53:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231615#M2699</guid>
      <dc:creator>JGerrity</dc:creator>
      <dc:date>2025-04-08T12:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231653#M2700</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;Try if the following works.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {
var assignedGroup = current.getValue('assignment_group');
var group = new GlideRecord('sys_user_group');
group.addQuery('sys_id', assignedGroup);
if (group.next()) {
	var isMemberRR = group.u_member_of_round_robin;
	gs.print("isMemberRR:" + isMemberRR);
	gs.log("isMemberRR:" + isMemberRR);
	if (isMemberRR == true) {
		var mem = new GlideRecord('sys_user_grmember');
		mem.addQuery('group', group.getValue('sys_id'));
		mem.orderBy('user.u_last_assigned_task_date');
		mem.query();
		if (mem.next() &amp;amp;&amp;amp; mem.user.u_outlook_out_of_office != '1') {
			current.assigned_to = mem.user;
		}
	}
}
})(current,previous);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 13:20:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231653#M2700</guid>
      <dc:creator>Sandeep Rajput</dc:creator>
      <dc:date>2025-04-08T13:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231742#M2701</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when is the business rule running? on which table and what's the condition?&lt;/P&gt;
&lt;P&gt;Your business rule should be Before insert/update.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {
    // Query the assignment group to check if u_roundrobin is true
    var group = new GlideRecord('sys_user_group');
    if (group.get(current.assignment_group) &amp;amp;&amp;amp; group.u_roundrobin) {
        // Query all members of the group who are not out of office
        var gMember = new GlideRecord('sys_user_grmember');
        gMember.addQuery('group', current.assignment_group);
        gMember.addQuery('user.u_out_of_office', false);
        gMember.query();

        // If there are members available, assign the incident to the first one found
        if (gMember.next()) {
            current.assigned_to = gMember.user;
        }
    }
})(current, previous);&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:12:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231742#M2701</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-08T14:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231798#M2703</link>
      <description>&lt;P&gt;I want to thank both&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/145583"&gt;@Sandeep Rajput&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;for helping with this.&amp;nbsp; Sandeep, really appreciate you pointing me in the right direction.&lt;BR /&gt;&lt;BR /&gt;Ankur, your formatting and logic were bang-on!&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you both, greatly appreciated!!&lt;BR /&gt;Jason&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:52:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231798#M2703</guid>
      <dc:creator>JGerrity</dc:creator>
      <dc:date>2025-04-08T14:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231802#M2704</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to help.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:54:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3231802#M2704</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-08T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238281#M2776</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/145583"&gt;@Sandeep Rajput&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;I'm looking to extend the functionality of this script and wondered if you had recommendations on logical approach (I'll try to figure out the coding part)...gotta learn right?&lt;BR /&gt;&lt;BR /&gt;What I'm looking to do is iterate through the members of all assignment groups that have the group.u_roundrobin field set to true.&amp;nbsp; &amp;nbsp;Add all of these users into an array, then convert all users to input for an API action that will use MS Graph to check the autoreply status of Exchange Online via a batch API call.&amp;nbsp; Then for all users who's autoreply status is enabled, set the u_outofoffice value to true on the user table.&lt;BR /&gt;&lt;BR /&gt;Basically, it's looking to set the out of office flag to true based upon Exchange Online AutoReply status daily so our users only have to maintain out of office in one location (Outlook).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm wondering is does this logic make sense?&amp;nbsp; iterate through the assignment groups, add users to array and then add each user to an input variable of a flow action (script step), which will then be used to make the graph API call.&lt;BR /&gt;&lt;BR /&gt;I was thinking a scheduled job (script) to only make the API call once or twice a day.&amp;nbsp; The script needs to find all group members of round robin, set those users' email addresses (UPN) as input variables to then be called by an Flow (Action) which makes the API batch call, to check only those users.&lt;BR /&gt;&lt;BR /&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 12:40:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238281#M2776</guid>
      <dc:creator>JGerrity</dc:creator>
      <dc:date>2025-04-15T12:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238285#M2777</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes you can use daily scheduled job and handle it&lt;/P&gt;
&lt;P&gt;something like this but please enhance&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function() {
    // Step 1: Collect all users in round-robin groups
    var users = [];
    var group = new GlideRecord('sys_user_group');
    group.addQuery('u_roundrobin', true);
    group.query();
    while (group.next()) {
        var gMember = new GlideRecord('sys_user_grmember');
        gMember.addQuery('group', group.sys_id);
        gMember.query();
        while (gMember.next()) {
            users.push(gMember.user.email.toString()); // Collect user email addresses
        }
    }

    // Step 2: Make API call to check AutoReply status
    var requestBody = {
        "requests": users.map(function(email) {
            return {
                "url": "/users/" + email + "/mailboxSettings",
                "method": "GET"
            };
        })
    };

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://graph.microsoft.com/v1.0/$batch');
    request.setHttpMethod('POST');
    request.setRequestHeader('Content-Type', 'application/json');
    request.setRequestHeader('Authorization', 'Bearer YOUR_ACCESS_TOKEN'); // Replace with your access token
    request.setRequestBody(JSON.stringify(requestBody));

    var response = request.execute();
    var responseBody = JSON.parse(response.getBody());

    // Step 3: Update u_out_of_office status based on API response
    responseBody.responses.forEach(function(res) {
        var email = res.id.split('/')[1];
        var autoReplyStatus = res.body.automaticRepliesStatus;

        var user = new GlideRecord('sys_user');
        user.addQuery('email', email);
        user.query();
        if (user.next()) {
            user.u_out_of_office = (autoReplyStatus === 'enabled');
            user.update();
        }
    });
})();&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 12:44:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238285#M2777</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-15T12:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238299#M2778</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;Wow!&amp;nbsp; not only a blazingly fast response but exactly what I was looking for.&amp;nbsp; You even did the coding part for me!&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Greatly appreciated thank you!&lt;BR /&gt;Jason&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 12:56:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238299#M2778</guid>
      <dc:creator>JGerrity</dc:creator>
      <dc:date>2025-04-15T12:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238387#M2781</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to help.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 13:49:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238387#M2781</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-15T13:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238791#M2790</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you again for this it's a great start!&lt;BR /&gt;&lt;BR /&gt;I noticed that the formatting of MS Graph batching is :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "requests": [
    {
      "id": "1",
   "url": "/users/" + email + "/mailboxSettings/automaticRepliesSetting",
      "method": "GET"
    },
    {
      "id": "2",
      "url": "/users/" + email + "/mailboxSettings/automaticRepliesSetting",
      "method": "GET"
    },
    {
      "id": "3",
      "url": "/users/" + email + "/mailboxSettings/automaticRepliesSetting",
     "method": "GET"
    },
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;So I'm thinking that the users array should be counted or I'm wondering if it's possible to build the response body inside the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; while (group.next()) {&lt;/PRE&gt;&lt;P&gt;loop.&lt;BR /&gt;&lt;BR /&gt;The request body is specific formatting with the combination of { "requests": [&lt;BR /&gt;Then each user is within a { }; and ID field is mandatory and then closed within the ]:&lt;BR /&gt;&lt;BR /&gt;As referenced here:&amp;nbsp;&lt;A title="Json batch request" href="https://learn.microsoft.com/en-us/graph/json-batching?tabs=http" target="_self"&gt;https://learn.microsoft.com/en-us/graph/json-batching?tabs=http&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm not sure how to write the exact format of the required requestBody with an incremental ID value.&lt;BR /&gt;&lt;BR /&gt;Cheers!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 20:01:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238791#M2790</guid>
      <dc:creator>JGerrity</dc:creator>
      <dc:date>2025-04-15T20:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Round Robin Business Rule script Question about addQuerry order for multiple custom fields</title>
      <link>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238924#M2792</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/728179"&gt;@JGerrity&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then inside the while loop form array of json objects and use it&lt;/P&gt;
&lt;P&gt;something like this&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function() {
    // Step 1: Collect all users in round-robin groups
    var users = [];
    var group = new GlideRecord('sys_user_group');
    group.addQuery('u_roundrobin', true);
    group.query();
    while (group.next()) {
        var gMember = new GlideRecord('sys_user_grmember');
        gMember.addQuery('group', group.sys_id);
        gMember.query();
        while (gMember.next()) {
            users.push(gMember.user.email.toString()); // Collect user email addresses
        }
    }

    // Step 2: Make API call to check AutoReply status
    var requestBody = {
        "requests": users.map(function(email, index) {
            return {
                "id": (index + 1).toString(), // Incremental ID value
                "url": "/users/" + email + "/mailboxSettings/automaticRepliesSetting",
                "method": "GET"
            };
        })
    };

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://graph.microsoft.com/v1.0/$batch');
    request.setHttpMethod('POST');
    request.setRequestHeader('Content-Type', 'application/json');
    request.setRequestHeader('Authorization', 'Bearer YOUR_ACCESS_TOKEN'); // Replace with your access token
    request.setRequestBody(JSON.stringify(requestBody));

    var response = request.execute();
    var responseBody = JSON.parse(response.getBody());

    // Step 3: Update u_out_of_office status based on API response
    responseBody.responses.forEach(function(res) {
        var email = res.id.split('/')[1];
        var autoReplyStatus = res.body.automaticRepliesStatus;

        var user = new GlideRecord('sys_user');
        user.addQuery('email', email);
        user.query();
        if (user.next()) {
            user.u_out_of_office = (autoReplyStatus === 'enabled');
            user.update();
        }
    });
})();&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 02:29:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/round-robin-business-rule-script-question-about-addquerry-order/m-p/3238924#M2792</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-16T02:29:14Z</dc:date>
    </item>
  </channel>
</rss>

