<?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 Calculate Due Date based on Time Zone in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768044#M339823</link>
    <description>&lt;P&gt;We have employee terminations that need to happen at certain times of the day based on time zone. If an employee is being terminated on 9/1 in the US/Eastern that employee termination should fire at 5:00pm at the end of 9/1. This works fine for that time zone. Now issue becomes if a Hong Kong employee is terminated then the end of day is 5:00pm in their time zone which in the EST time zone would be 5:00AM as there is a 12 hour time difference. I have tried several scripts and here is my current one and I cannot seem to get the due date to reflect when orchestration should begin:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gs.include('DurationCalculator');&lt;/P&gt;&lt;P&gt;executeSample();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function executeSample() {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // First we need a DurationCalculator object.&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var dc = new DurationCalculator();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// -------------- Add a schedule to the date calculator ---------------------&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; addSchedule(dc);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //dc.setTimeZone("GMT+8")&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; dc.setStartDateTime("8/31/2017 00:00:00");&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!dc.calcDuration(9*3600)) { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // 2 days&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log("*** Error calculating duration");&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log(dc.getEndDateTime());&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function addSchedule(durationCalculator) {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // &amp;nbsp; Load the "8-6 weekdays" schedule into our duration calculator.&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var scheduleName = "8-6 weekdays";&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var grSched = new GlideRecord('cmn_schedule');&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; grSched.addQuery('name', scheduleName);&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; grSched.query();&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!grSched.next()) {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log('*** Could not find schedule "' + scheduleName + '"');&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
    <pubDate>Fri, 01 Sep 2017 21:02:58 GMT</pubDate>
    <dc:creator>ArithaW</dc:creator>
    <dc:date>2017-09-01T21:02:58Z</dc:date>
    <item>
      <title>Calculate Due Date based on Time Zone</title>
      <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768044#M339823</link>
      <description>&lt;P&gt;We have employee terminations that need to happen at certain times of the day based on time zone. If an employee is being terminated on 9/1 in the US/Eastern that employee termination should fire at 5:00pm at the end of 9/1. This works fine for that time zone. Now issue becomes if a Hong Kong employee is terminated then the end of day is 5:00pm in their time zone which in the EST time zone would be 5:00AM as there is a 12 hour time difference. I have tried several scripts and here is my current one and I cannot seem to get the due date to reflect when orchestration should begin:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gs.include('DurationCalculator');&lt;/P&gt;&lt;P&gt;executeSample();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function executeSample() {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // First we need a DurationCalculator object.&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var dc = new DurationCalculator();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// -------------- Add a schedule to the date calculator ---------------------&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; addSchedule(dc);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //dc.setTimeZone("GMT+8")&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; dc.setStartDateTime("8/31/2017 00:00:00");&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!dc.calcDuration(9*3600)) { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // 2 days&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log("*** Error calculating duration");&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log(dc.getEndDateTime());&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function addSchedule(durationCalculator) {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // &amp;nbsp; Load the "8-6 weekdays" schedule into our duration calculator.&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var scheduleName = "8-6 weekdays";&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var grSched = new GlideRecord('cmn_schedule');&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; grSched.addQuery('name', scheduleName);&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; grSched.query();&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!grSched.next()) {&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.log('*** Could not find schedule "' + scheduleName + '"');&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 21:02:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768044#M339823</guid>
      <dc:creator>ArithaW</dc:creator>
      <dc:date>2017-09-01T21:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Due Date based on Time Zone</title>
      <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768045#M339824</link>
      <description>&lt;P&gt;I figured out my issue. &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Sep 2017 21:13:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768045#M339824</guid>
      <dc:creator>ArithaW</dc:creator>
      <dc:date>2017-09-01T21:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Due Date based on Time Zone</title>
      <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768046#M339825</link>
      <description>&lt;P&gt;What was the solution to this? Could you provide the details?&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Nov 2017 19:16:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768046#M339825</guid>
      <dc:creator>pranavparmar</dc:creator>
      <dc:date>2017-11-28T19:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Due Date based on Time Zone</title>
      <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768047#M339826</link>
      <description>&lt;P&gt;I need to account for Daylight Savings time so I added a line in the code to determine if the date selected was using Daylight savings time. I also added schedules at the locations and had the script look at the location of the terminated user to determine which timezone to use.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Final Script:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gs.include('DurationCalculator');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;executeSample();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function executeSample() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;// First we need a DurationCalculator object.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var dc = new DurationCalculator();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;// Load a schedule.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; addSchedule(dc);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;// Compute a duration using the schedule.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var termDate = new GlideDateTime(current.variables.effective_date); &amp;nbsp; //initialize startTime&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var isDST = termDate.isDST(); &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gs.log('Termination Date is ' + termDate + "Daylight savings is " + isDST);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//dc.setTimeZone("GMT+7");&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;dc.setStartDateTime(termDate);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (!isDST){&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (!dc.calcDuration(10*3600)) { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // 2 days&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gs.log("*** Error calculating duration");&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;return;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;else {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (!dc.calcDuration(9*3600)) { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // 2 days&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gs.log("*** Error calculating duration");&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;return;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //gs.log(dc.getEndDateTime()); &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.due_date = dc.getEndDateTime();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function addSchedule(durationCalculator) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; // &amp;nbsp; Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; var scheduleName = current.variables.location.u_schedule.name;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; gs.log('Location schedule is ' + scheduleName);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; var grSched = new GlideRecord('cmn_schedule');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; grSched.addQuery('name', scheduleName);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; grSched.query();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; if (!grSched.next()) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; gs.log('*** Could not find schedule "' + scheduleName + '"');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; return;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; }&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Nov 2017 19:23:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768047#M339826</guid>
      <dc:creator>ArithaW</dc:creator>
      <dc:date>2017-11-28T19:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Due Date based on Time Zone</title>
      <link>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768048#M339827</link>
      <description>&lt;P&gt;Hi @aritha,&lt;/P&gt;
&lt;P&gt;I have the same requirement to trigger the flow Designer at Termination dateTime in user's local timezone. Can you please help me understand the script which you have posted, where you have written this and the inputs that are required for this script.&lt;/P&gt;
&lt;P&gt;I will try to create an action and pass the inputs and output the duration on how much time the flow should wait&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 11:07:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/calculate-due-date-based-on-time-zone/m-p/768048#M339827</guid>
      <dc:creator>Nalinakshi Rag1</dc:creator>
      <dc:date>2020-10-05T11:07:37Z</dc:date>
    </item>
  </channel>
</rss>

