<?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 Script Help to exclude weekends in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580071#M1003884</link>
    <description>&lt;P&gt;I have a custom True/False field, i wanted to make the field set as true when the Assignment Group for the case is empty for more than 1 business days..&lt;BR /&gt;Someone please help how to achieve this&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2023 08:21:41 GMT</pubDate>
    <dc:creator>Jyoti Tripathi</dc:creator>
    <dc:date>2023-06-06T08:21:41Z</dc:date>
    <item>
      <title>Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580071#M1003884</link>
      <description>&lt;P&gt;I have a custom True/False field, i wanted to make the field set as true when the Assignment Group for the case is empty for more than 1 business days..&lt;BR /&gt;Someone please help how to achieve this&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 08:21:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580071#M1003884</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-06T08:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580087#M1003894</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;: please help&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 08:46:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580087#M1003894</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-06T08:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580103#M1003901</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/74156"&gt;@Jyoti Tripathi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;To automatically set a custom True/False field to "True" when the Assignment Group for a case is empty for more than one business day, you can use a Business Rule in ServiceNow. Here's an example&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function executeRule(current, previous,) {
  // Check if the Assignment Group is empty
  if (!current.assignment_group.nil()) {
    return;
  }

  // Check if the case has been empty for more than one business day
  var oneBusinessDay = 60 * 60 * 24; // Adjust if your business days have different durations
  var now = new GlideDateTime();
  var createdOn = new GlideDateTime(current.sys_created_on);
  var elapsedDays = GlideDateTime.subtract(now, createdOn).getNumericValue() / oneBusinessDay;

  if (elapsedDays &amp;gt;= 1) {
    // Set the custom field to "True"
    current.u_custom_field = true;
  }
})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When to Run : "Before" and "After"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Table : incident (if it is incident)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Shravan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Please mark it as helpful and correct answer, if this helps you&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 08:57:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580103#M1003901</guid>
      <dc:creator>Sai Shravan</dc:creator>
      <dc:date>2023-06-06T08:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580109#M1003904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/294347"&gt;@Sai Shravan&lt;/a&gt;&amp;nbsp;: The above code will not exclude weekends. Also Business Rule will work for this...how about a Schedule job?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 09:04:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580109#M1003904</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-06T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580121#M1003909</link>
      <description>&lt;P&gt;Firstly it is good to have this information how long your assignemnt group is empty. You can take it from audit table, but it is not efficient way to search this way, so you want to somehow mark this time to get it easly accesible. Separate column which is calculated from business rule may help. It would store time when group become unasigned or incident with empty group has been created. And once incident is assinged you can clear whis field by same business rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you have it you can schedule action to raise you flag for such incidents. You can in your previous business rule schedule event and write script action which will mark youd field true if in the meantime it was not assigned (your time field will tell you that). Alternatively you can write Scheduled Script Execution (sysauto_script) job to search incident table by your time field and set value of your flag with updateMultiple() method for your incident GlideRecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For excluding weekends you can use&amp;nbsp;GlideSchedule API which can tell you about elapsed time based on some schedule (like excluding weekends)&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 09:26:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580121#M1003909</guid>
      <dc:creator>Grzegorz Kaznoc</dc:creator>
      <dc:date>2023-06-06T09:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580154#M1003922</link>
      <description>&lt;P&gt;Hi Jyoti,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please try below code in scheduled job, value of iDay 6 and 7 are referring&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;6 = Saturday&lt;/LI&gt;&lt;LI&gt;7 = Sunday&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;var grCase = new GlideRecord('&amp;lt;TABLE_NAME&amp;gt;');
grCase.addEncodedQuery('active=true^assignment_group=NULL');
grCase.query();

while(grCase.next()){
	var gdtCreated = new GlideDateTime(grCase.getValue('sys_created_on'));

	var bIsWorkingDay = false;

	do {
		var iDay = gdtCreated.getDayOfWeekLocalTime();

		gdtCreated.addDaysLocalTime(1);

		if((iDay!=6) &amp;amp;&amp;amp; (iDay!=7)){
			bIsWorkingDay = true;
		}
	} while (!bIsWorkingDay);

	var gdtCurrent = new GlideDateTime();

	//gs.print(gdtCreated);
	//gs.print(gdtCurrent);

	if(gdtCreated &amp;lt; gdtCurrent) {
		grCase.setValue('CUSTOM_FIELD_NAME', true);
		grCase.update();
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Bala&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 10:03:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580154#M1003922</guid>
      <dc:creator>Baala T</dc:creator>
      <dc:date>2023-06-06T10:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580164#M1003926</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/74156"&gt;@Jyoti Tripathi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can schedule job daily and check if the group field is empty and it has been more than 1 business day&lt;/P&gt;
&lt;P&gt;business day calculation is already shared with you&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 10:13:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580164#M1003926</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-06-06T10:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580206#M1003935</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/285873"&gt;@Baala T&lt;/a&gt;&amp;nbsp;: Thanks for sharing the script, what if the case got created on weekend and group was empty (example on Saturday).. so on Tuesday(More than 1 business days) it will make the field set as true right?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 11:10:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580206#M1003935</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-06T11:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580208#M1003936</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;: Apologies, i am not able to see the calculation shared by you.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 11:12:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580208#M1003936</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-06T11:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580236#M1003947</link>
      <description>&lt;P&gt;Modified the script little bit. PFB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var gdtCreated = new GlideDateTime('2023-06-02 09:27:56');
gs.print('Actual Created Date &amp;amp; Time : ' + gdtCreated);

var bIsWorkingDay = false;
var bCheckCreatedInNonBusinessDays = false;

do {
    var iCreatedDay = gdtCreated.getDayOfWeekLocalTime();

    if(!bCheckCreatedInNonBusinessDays){
        //Is it created on Saturday
        if (iCreatedDay==6){
            gdtCreated.addDaysLocalTime(1);		
        }

        //Check if it is falls on Sunday
        iCreatedDay = gdtCreated.getDayOfWeekLocalTime();
        if (iCreatedDay==7){
            gdtCreated.addDaysLocalTime(1);		
        }

        bCheckCreatedInNonBusinessDays = true;
        gs.print('Business Start Date &amp;amp; Time : ' + gdtCreated);
    }

    //Add a Business Day
    gdtCreated.addDaysLocalTime(1);
    
    var iBusinessDay = gdtCreated.getDayOfWeekLocalTime();

    gs.print(iBusinessDay + '&amp;lt;&amp;gt;' + gdtCreated)

    if((iBusinessDay!=6) &amp;amp;&amp;amp; (iBusinessDay!=7)) {
        bIsWorkingDay = true;
    }
} while (!bIsWorkingDay);

var gdtCurrent = new GlideDateTime();

gs.print('Business End Date &amp;amp; Time : ' + gdtCreated);
gs.print('Current Date &amp;amp; Time : ' + gdtCurrent);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 11:42:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2580236#M1003947</guid>
      <dc:creator>Baala T</dc:creator>
      <dc:date>2023-06-06T11:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581282#M1004337</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/285873"&gt;@Baala T&lt;/a&gt;&amp;nbsp;:&lt;BR /&gt;it is not make the Custom field to set it as true when Assignment group is empty for more than 1 business days, please help&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 09:34:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581282#M1004337</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-07T09:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581290#M1004341</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/74156"&gt;@Jyoti Tripathi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;calculation is shared by other members.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 09:39:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581290#M1004341</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-06-07T09:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581306#M1004352</link>
      <description>&lt;P&gt;Hope you have created as a scheduled job, What is the error that you are getting?&lt;/P&gt;&lt;P&gt;Let me know the Table Name and Field Name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 10:04:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581306#M1004352</guid>
      <dc:creator>Baala T</dc:creator>
      <dc:date>2023-06-07T10:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help to exclude weekends</title>
      <link>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581311#M1004355</link>
      <description>&lt;P&gt;Table is sn_hr_core_case and field name is assignment_check1bd&lt;BR /&gt;This is how i want this to work-&lt;BR /&gt;&lt;SPAN&gt;if the case got created on Monday and group was empty.. so on Tuesday(More than 1 business days) it will make the field set as true&lt;BR /&gt;if the case got created on Tuesday and group was empty.. so on Wednesday..it will make the field set as true.. and so on..&lt;BR /&gt;&lt;STRONG&gt;But &lt;/STRONG&gt;if the case got created on Saturday/Sunday and group was empty.. so on Tuesday (More than 1 business days) it will make the field set as true&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 10:12:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/script-help-to-exclude-weekends/m-p/2581311#M1004355</guid>
      <dc:creator>Jyoti Tripathi</dc:creator>
      <dc:date>2023-06-07T10:12:58Z</dc:date>
    </item>
  </channel>
</rss>

