<?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 Field type &amp;quot;schedule_date_time&amp;quot; in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874286#M531212</link>
    <description>&lt;P&gt;I'm trying to write a glide record query against the cmn_schedule_span table and want to restrict the records returned by the start_date_time and the end_date_time on this table. I'm using the data to write a schedule page timeline.&lt;BR /&gt;&lt;BR /&gt;My script is having problems as the start_date_time and end_date_time are of type "schedule_date_time".&lt;BR /&gt;&lt;BR /&gt;I tried this and many variants, but could not get the desired result within the gliderecord:&lt;BR /&gt;(for example tried using a GlideDate, etc)&lt;BR /&gt;&lt;BR /&gt;var _userID = '46d44a23a9fe19810012d100cca80666';&lt;BR /&gt;var start = new GlideDateTime('2011-10-19 20:00:00');&lt;BR /&gt;var end = new GlideDateTime('2012-05-01 07:17:42');&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt; schedRec.addQuery('schedule.u_schedule_user', '=', _userID);&lt;BR /&gt; schedRec.addQuery('Type', '=', 'Time off');&lt;BR /&gt; schedRec.addQuery('start_date_time', '&amp;lt;=', end); // constrain the leave to the time bounds of&lt;BR /&gt; schedRec.addQuery('end_date_time', '&amp;gt;=', start); // the task we are allocating. &lt;BR /&gt; schedRec.query();&lt;BR /&gt; while (schedRec.next()) {&lt;BR /&gt; .....process the selected records.&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;I then tried to use an encoded query, and was surprised to see the only filter criteria I could use was, "is", "is not" or "is anything".&lt;BR /&gt;&lt;BR /&gt;So given I was suitably stumped, I ended up returning all records for the complete data range, and then used script to only process the records I desired:&lt;BR /&gt;&lt;BR /&gt;var _userID = '46d44a23a9fe19810012d100cca80666';&lt;BR /&gt;var start = new GlideDateTime('2011-10-19 20:00:00');&lt;BR /&gt;var end = new GlideDateTime('2012-05-01 07:17:42');&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt; schedRec.addQuery('schedule.u_schedule_user', '=', _userID);&lt;BR /&gt; schedRec.addQuery('Type', '=', 'Time off');&lt;BR /&gt; schedRec.query();&lt;BR /&gt; while (schedRec.next()) {&lt;BR /&gt; var leaveStart = schedRec.start_date_time.getGlideObject().getGlideDateTime();&lt;BR /&gt; var leaveEnd = schedRec.end_date_time.getGlideObject().getGlideDateTime();&lt;BR /&gt; if (( leaveStart &amp;lt;= end) &amp;amp;&amp;amp; (leaveEnd &amp;gt;= start)) { &lt;BR /&gt; .....process the selected records.&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;While my second script provides the correct data, I'm concerned the runtime is longer than it should be, as it is returning more from the database than it needs to.&lt;BR /&gt;&lt;BR /&gt;Can anyone help???&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2011 06:32:38 GMT</pubDate>
    <dc:creator>carl_hensley</dc:creator>
    <dc:date>2011-12-07T06:32:38Z</dc:date>
    <item>
      <title>Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874286#M531212</link>
      <description>&lt;P&gt;I'm trying to write a glide record query against the cmn_schedule_span table and want to restrict the records returned by the start_date_time and the end_date_time on this table. I'm using the data to write a schedule page timeline.&lt;BR /&gt;&lt;BR /&gt;My script is having problems as the start_date_time and end_date_time are of type "schedule_date_time".&lt;BR /&gt;&lt;BR /&gt;I tried this and many variants, but could not get the desired result within the gliderecord:&lt;BR /&gt;(for example tried using a GlideDate, etc)&lt;BR /&gt;&lt;BR /&gt;var _userID = '46d44a23a9fe19810012d100cca80666';&lt;BR /&gt;var start = new GlideDateTime('2011-10-19 20:00:00');&lt;BR /&gt;var end = new GlideDateTime('2012-05-01 07:17:42');&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt; schedRec.addQuery('schedule.u_schedule_user', '=', _userID);&lt;BR /&gt; schedRec.addQuery('Type', '=', 'Time off');&lt;BR /&gt; schedRec.addQuery('start_date_time', '&amp;lt;=', end); // constrain the leave to the time bounds of&lt;BR /&gt; schedRec.addQuery('end_date_time', '&amp;gt;=', start); // the task we are allocating. &lt;BR /&gt; schedRec.query();&lt;BR /&gt; while (schedRec.next()) {&lt;BR /&gt; .....process the selected records.&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;I then tried to use an encoded query, and was surprised to see the only filter criteria I could use was, "is", "is not" or "is anything".&lt;BR /&gt;&lt;BR /&gt;So given I was suitably stumped, I ended up returning all records for the complete data range, and then used script to only process the records I desired:&lt;BR /&gt;&lt;BR /&gt;var _userID = '46d44a23a9fe19810012d100cca80666';&lt;BR /&gt;var start = new GlideDateTime('2011-10-19 20:00:00');&lt;BR /&gt;var end = new GlideDateTime('2012-05-01 07:17:42');&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt; schedRec.addQuery('schedule.u_schedule_user', '=', _userID);&lt;BR /&gt; schedRec.addQuery('Type', '=', 'Time off');&lt;BR /&gt; schedRec.query();&lt;BR /&gt; while (schedRec.next()) {&lt;BR /&gt; var leaveStart = schedRec.start_date_time.getGlideObject().getGlideDateTime();&lt;BR /&gt; var leaveEnd = schedRec.end_date_time.getGlideObject().getGlideDateTime();&lt;BR /&gt; if (( leaveStart &amp;lt;= end) &amp;amp;&amp;amp; (leaveEnd &amp;gt;= start)) { &lt;BR /&gt; .....process the selected records.&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;While my second script provides the correct data, I'm concerned the runtime is longer than it should be, as it is returning more from the database than it needs to.&lt;BR /&gt;&lt;BR /&gt;Can anyone help???&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2011 06:32:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874286#M531212</guid>
      <dc:creator>carl_hensley</dc:creator>
      <dc:date>2011-12-07T06:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874287#M531213</link>
      <description>&lt;P&gt;You can see differences between the data in the two fields if you run the following script in the background.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;BR /&gt;&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt;schedRec.query();&lt;BR /&gt;if(schedRec.next()){&lt;BR /&gt;    gs.print(new GlideDateTime('2011-10-19 20:00:00').getValue());&lt;BR /&gt;    gs.print(schedRec.start_date_time);&lt;BR /&gt;}&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;The way the data is stored in the fields differs greatly, as well as their object definition. I worked up a bit of script to make this work:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;BR /&gt;&lt;BR /&gt;function timeISOConvertor(x){&lt;BR /&gt;x = x.getRaw();&lt;BR /&gt;var dt = new Packages.java.text.SimpleDateFormat();&lt;BR /&gt;dt.applyPattern('yyyy');&lt;BR /&gt;var ye = dt.format(x).toString();&lt;BR /&gt;dt.applyPattern('MM');&lt;BR /&gt;var mo = dt.format(x).toString();&lt;BR /&gt;dt.applyPattern('dd');&lt;BR /&gt;var da = dt.format(x).toString();&lt;BR /&gt;dt.applyPattern('H');&lt;BR /&gt;var ho = dt.format(x).toString();&lt;BR /&gt;dt.applyPattern('m');&lt;BR /&gt;var mi = dt.format(x).toString();&lt;BR /&gt;dt.applyPattern('ss');&lt;BR /&gt;var se = dt.format(x).toString();&lt;BR /&gt;&lt;BR /&gt;var ret = ye+mo+da+'T'+ho+mi+se;&lt;BR /&gt;return ret;&lt;BR /&gt;}&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now if you try it you will see the difference. Just make sure you parse your GlideDateTime with the function, and your good to go.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;var x = timeISOConvertor(new GlideDateTime('2011-07-19 20:00:10'));&lt;BR /&gt;var schedRec = new GlideRecord('cmn_schedule_span');&lt;BR /&gt;schedRec.addQuery('start_date_time', '&amp;lt;=', x);&lt;BR /&gt;schedRec.query();&lt;BR /&gt;&lt;BR /&gt;while(schedRec.next()){&lt;BR /&gt;    gs.print(schedRec.start_date_time); //resulting data&lt;BR /&gt;}&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Hope it helps,&lt;BR /&gt;&lt;BR /&gt;Wesley&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Dec 2011 10:33:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874287#M531213</guid>
      <dc:creator>w_bouwer</dc:creator>
      <dc:date>2011-12-07T10:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874288#M531214</link>
      <description>&lt;P&gt;Works like a treat.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thankyou very much!&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Dec 2011 22:41:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874288#M531214</guid>
      <dc:creator>carl_hensley</dc:creator>
      <dc:date>2011-12-07T22:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874289#M531215</link>
      <description>&lt;P&gt;Note that a "schedule_date_time" can't always be precisely represented by a GlideDateTime, because they don't don't usually specify a specific timezone. Most Schedules are defined as "floating".&lt;BR /&gt;&lt;BR /&gt;When you convert one into a GlideDateTime you are 'fixing' it according to your own session timezone.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Dec 2011 11:57:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874289#M531215</guid>
      <dc:creator />
      <dc:date>2011-12-13T11:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874290#M531216</link>
      <description>&lt;P&gt;Thanks James, &lt;BR /&gt;&lt;BR /&gt;That is good to know.&lt;BR /&gt;&lt;BR /&gt;cheers,&lt;BR /&gt;carl&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Dec 2011 21:33:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/1874290#M531216</guid>
      <dc:creator>carl_hensley</dc:creator>
      <dc:date>2011-12-13T21:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Field type "schedule_date_time"</title>
      <link>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/3074405#M1153007</link>
      <description>&lt;P&gt;Any idea why it is failing to correctly convert these dates:&lt;/P&gt;&lt;P&gt;Values on change record:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DEBUG JS: start date = 26/10/2024 08:26:06 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DEBUG JS: end date = 30/10/2024 08:26:08 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ISO conversion - setting date to the day before:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DEBUG JS: iso start date = 20241025T17000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DEBUG JS: iso end date = 20241029T17000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 15:23:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/field-type-quot-schedule-date-time-quot/m-p/3074405#M1153007</guid>
      <dc:creator>jtshone</dc:creator>
      <dc:date>2024-10-15T15:23:03Z</dc:date>
    </item>
  </channel>
</rss>

