<?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: Due date script in flow designer returns incorrect value in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017711#M1138006</link>
    <description>&lt;P&gt;Try like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;

// Initialize the GlideDateTime with the event date
var endDateTime = new GlideDateTime();
endDateTime.setDisplayValue(endDate + ' 17:00:00'); // Set to 5 PM ET
gs.log('Event DateTime (5 PM ET): ' + endDateTime.getDisplayValue());

// Define the schedule (8-5 weekdays excluding holidays)
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');

// Add 3 business days to the event date
var dueDate = sched.add(endDateTime, new GlideDuration('3 00:00:00'));

// The resulting due date should also be at 5 PM ET on that date.
dueDate.setDisplayValue(dueDate.getDisplayValue().split(' ')[0] + ' 17:00:00');
gs.log('Due DateTime after adding 3 business days: ' + dueDate.getDisplayValue());

// Check the UTC time of the due date
gs.log('Due DateTime in UTC: ' + dueDate.getValue());

// Output the due date in ET (should already be in the correct time zone)
gs.log('Final DueDate in ET: ' + dueDate.getDisplayValue());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're still having issues, double-check the time zone on the schedule itself.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2024 23:56:42 GMT</pubDate>
    <dc:creator>Sheldon  Swift</dc:creator>
    <dc:date>2024-08-13T23:56:42Z</dc:date>
    <item>
      <title>Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017643#M1137991</link>
      <description>&lt;P&gt;I have this script on a Catalog task Due date field. It's supposed to set the due date of the task to 5pm ET 3 days after an event date. Our instance is set to ET, and the schedule and child schedule is set to ET.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the script, the logs show 5pm on the due date, but when it actually sets the value of the due date field on the task, it sets it to 1pm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;
var endDateTime = new GlideDateTime(endDate);
gs.log('EndDateTime: ' + endDateTime,"KC"); //Returns 2024-08-30 00:00:00
endDateTime.addSeconds(61200); //Set date to 5pm on date of event (17hrs*60mins*60secs)
gs.log('EndDateTime: ' + endDateTime,"KC"); //Returns 2024-08-30 17:00:00
var dur = new GlideDuration('0 27:00:00'); //3 days = 27 hours on an 8-5 schedule
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var dueDate = sched.add(endDateTime,dur);
gs.log('DueDate: ' + dueDate,"KC"); //Returns 2024-08-30 17:00:00
return dueDate; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Seems like it's seeing the due date as the UTC time, and then setting it to ET in the task. How do I fix this?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 20:40:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017643#M1137991</guid>
      <dc:creator>kchorny</dc:creator>
      <dc:date>2024-08-13T20:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017687#M1138000</link>
      <description>&lt;P&gt;In the context of which user does your script run? What time zone is set in that user's profile?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 22:36:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017687#M1138000</guid>
      <dc:creator>Slava Savitsky</dc:creator>
      <dc:date>2024-08-13T22:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017711#M1138006</link>
      <description>&lt;P&gt;Try like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;

// Initialize the GlideDateTime with the event date
var endDateTime = new GlideDateTime();
endDateTime.setDisplayValue(endDate + ' 17:00:00'); // Set to 5 PM ET
gs.log('Event DateTime (5 PM ET): ' + endDateTime.getDisplayValue());

// Define the schedule (8-5 weekdays excluding holidays)
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');

// Add 3 business days to the event date
var dueDate = sched.add(endDateTime, new GlideDuration('3 00:00:00'));

// The resulting due date should also be at 5 PM ET on that date.
dueDate.setDisplayValue(dueDate.getDisplayValue().split(' ')[0] + ' 17:00:00');
gs.log('Due DateTime after adding 3 business days: ' + dueDate.getDisplayValue());

// Check the UTC time of the due date
gs.log('Due DateTime in UTC: ' + dueDate.getValue());

// Output the due date in ET (should already be in the correct time zone)
gs.log('Final DueDate in ET: ' + dueDate.getDisplayValue());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're still having issues, double-check the time zone on the schedule itself.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 23:56:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3017711#M1138006</guid>
      <dc:creator>Sheldon  Swift</dc:creator>
      <dc:date>2024-08-13T23:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018185#M1138177</link>
      <description>&lt;P&gt;Thank you!!! This worked like magic! The only exception is that I had to change the GlideDuration from '3 00:00:00' to '0 27:00:00'. Otherwise it added 8 days ((3 days*24 hours)/9 business hours) instead of 3.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 11:53:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018185#M1138177</guid>
      <dc:creator>kchorny</dc:creator>
      <dc:date>2024-08-14T11:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018218#M1138185</link>
      <description>&lt;P&gt;Be careful with parsing date/time display values. GlideDateTime objects' getDisplayValue() method returns the date and time in the &lt;EM&gt;current user&lt;/EM&gt;'s display format and time zone. It can have a different value and syntax depending on which user's context the script will run in.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 12:24:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018218#M1138185</guid>
      <dc:creator>Slava Savitsky</dc:creator>
      <dc:date>2024-08-14T12:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Due date script in flow designer returns incorrect value</title>
      <link>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018276#M1138201</link>
      <description>&lt;P&gt;Great point,&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/320349"&gt;@Slava Savitsky&lt;/a&gt;. Let’s correct that and offer an alternative solution using methods that work independently of user-specific settings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;

// Initialize the GlideDateTime with the event date
var endDateTime = new GlideDateTime();
endDateTime.setValue(endDate + ' 21:00:00'); // Set to 5 PM ET, which is 21:00:00 UTC
gs.log('Event DateTime (5 PM ET): ' + endDateTime.getValue()); // Using getValue() for consistency (UTC time)

// Define the schedule (8-5 weekdays excluding holidays)
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');

// Add 3 business days to the event date
var dueDate = sched.add(endDateTime, new GlideDuration('0 27:00:00'));

// The resulting due date should also be at 5 PM ET on that date.
var dueDateValue = dueDate.getValue().split(' ')[0] + ' 21:00:00'; // Adjust to 21:00:00 UTC which is 5 PM ET
dueDate.setValue(dueDateValue);
gs.log('Due DateTime after adding 3 business days: ' + dueDate.getValue()); // Using getValue() for consistency (UTC time)

// getValue provides UTC
gs.log('Final DueDate in UTC: ' + dueDate.getValue());

// getDisplayValue provides ET
gs.log('Final DueDate in ET: ' + dueDate.getDisplayValue());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 13:02:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/due-date-script-in-flow-designer-returns-incorrect-value/m-p/3018276#M1138201</guid>
      <dc:creator>Sheldon  Swift</dc:creator>
      <dc:date>2024-08-14T13:02:21Z</dc:date>
    </item>
  </channel>
</rss>

