<?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: Issue Parsing getDurationValue() Equalling 5 Days or More in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2571371#M1000693</link>
    <description>&lt;P&gt;Fixed with the following example, it seems that by retrieved time somehow reverted back to D HH:MM:SS format but now works as expected:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get length of time ticket has been open in days, hours, minutes, seconds
var diff2 = GlideDateTime.subtract(new GlideDateTime(gr.sys_created_on), new GlideDateTime());
var timeOpenMS = diff2.getDurationValue();
// Runs when a ticket is viewed from the service protal &amp;gt; my tickets &amp;gt; incident
gs.info("The duration of this ticket is: " + diff2.getDurationValue()); //syslog_list.do&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example conditions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set escalation widget to false by default
if (timeOpenMS &amp;lt; "04:00:00" &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp; gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp;
            (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
            data.showWidget = false;
            data.showEscalate = false;
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt; if (timeOpenMS &amp;gt; "5 00:00:00" &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp;
                (gr.priority == 1 || gr.priority == 2 || gr.priority == 3 || gr.priority == 4) &amp;amp;&amp;amp;
                (gr.incident_state == 1 || gr.incident_state == 2) &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp;
                gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp;
                (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
                data.showWidget = true;
                data.showEscalate = true;
                vEscalate = 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2023 12:59:37 GMT</pubDate>
    <dc:creator>Wasdom_Kung</dc:creator>
    <dc:date>2023-05-25T12:59:37Z</dc:date>
    <item>
      <title>Issue Parsing getDurationValue() Equalling 5 Days or More</title>
      <link>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2570512#M1000406</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a script that shows a widget based on the duration a ticket has been open, it's priority and some other factors. Currently, when a new ticket is logged, the widget should not show, however when going through the script debugger, 120:00:00 always evaluates to true, despite the ticket ages being minutes old, could someone explain this?&lt;BR /&gt;&lt;BR /&gt;I have previous methods before this that execute properly, such as 04:00:00, 24:00:00 and 72:00:00.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OpenTimeMS is calculated by:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get length of time ticket has been open in days, hours, minutes, seconds
var diff2 = GlideDateTime.subtract(new GlideDateTime(gr.sys_created_on), new GlideDateTime());
var timeOpenMS = diff2.getDurationValue();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Incidents open for 5 days or longer, escalation is 0, priority is 1, 2, 3 or 4
// State is new or work in progress, escalation 0, priority is 1, 2, 3 or 4
if (timeOpenMS &amp;gt; "120:00:00" &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp; gr.priority == 1 || gr.priority == 2 || gr.priority == 3 || gr.priority == 4 &amp;amp;&amp;amp; gr.incident_state == 1 || gr.incident_state == 2 &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp; gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp; (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
        data.showWidget = true;
        data.showEscalate = true;
        vEscalate = 0;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 15:43:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2570512#M1000406</guid>
      <dc:creator>Wasdom_Kung</dc:creator>
      <dc:date>2023-05-24T15:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Parsing getDurationValue() Equalling 5 Days or More</title>
      <link>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2570998#M1000557</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/267682"&gt;@Wasdom_Kung&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are comparing the duration value as a string. To properly compare the duration, you can convert it to a numeric value.&lt;/P&gt;&lt;P&gt;Here's an updated version of the comparison:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var timeOpen = new GlideDuration(timeOpenMS);
var timeOpenValue = timeOpen.getNumericValue();

// Compare timeOpenValue to the threshold
if (timeOpenValue &amp;gt; 120 &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp;
    (gr.priority == 1 || gr.priority == 2 || gr.priority == 3 || gr.priority == 4) &amp;amp;&amp;amp;
    (gr.incident_state == 1 || gr.incident_state == 2) &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp;
    gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp;
    (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
    data.showWidget = true;
    data.showEscalate = true;
    vEscalate = 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ratnakar&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 06:24:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2570998#M1000557</guid>
      <dc:creator>Ratnakar7</dc:creator>
      <dc:date>2023-05-25T06:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Parsing getDurationValue() Equalling 5 Days or More</title>
      <link>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2571156#M1000620</link>
      <description>&lt;P&gt;Hi Ratnakar,&lt;BR /&gt;&lt;BR /&gt;I've made the following changes as you suggested, it looks like it works but for this example ticket, that has been open for 24 hours, still evaluates true in debugging at 120 (5 days) of being open hmmm, it successfully evaluates as false for the 4, 24 and 72 statements.&lt;BR /&gt;&lt;BR /&gt;Changes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get length of time ticket has been open in days, hours, minutes, seconds
var diff2 = GlideDateTime.subtract(new GlideDateTime(gr.sys_created_on), new GlideDateTime());
var timeOpenMS = diff2.getDurationValue();
	
var timeOpen = new GlideDuration(timeOpenMS);
var timeOpenValue = timeOpen.getNumericValue();

// Incidents open for 5 days or longer, escalation is 0, priority is 1, 2, 3 or 4
// State is new or work in progress, escalation 0, priority is 1, 2, 3 or 4
if (timeOpenValue &amp;gt; 120 &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp; gr.priority == 1 || gr.priority == 2 || gr.priority == 3 || gr.priority == 4 &amp;amp;&amp;amp; gr.incident_state == 1 || gr.incident_state == 2 &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp; gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp; (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
        data.showWidget = true;
        data.showEscalate = true;
        vEscalate = 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;BR /&gt;Upon checking sys_log it looks like it's because the duration now shows as "&lt;SPAN&gt;The duration of this ticket is: 69367000" which is 0.8 days, so I don't think the conversion for timeOpenMS to timeOpenValue is working correctly.&lt;BR /&gt;&lt;BR /&gt;I output the value of diff2 before any conversion and this is the value returned, I believe this is causing the issue?&lt;BR /&gt;&amp;nbsp;1970-01-01 20:38:28&lt;BR /&gt;&lt;BR /&gt;Edit 2:&lt;BR /&gt;Actually didn't notice some other syntax changes in your provided code, I've modified 120 to 5 days in milliseconds which is&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;432000000 and tested and it has worked now, thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 10:55:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2571156#M1000620</guid>
      <dc:creator>Wasdom_Kung</dc:creator>
      <dc:date>2023-05-25T10:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Parsing getDurationValue() Equalling 5 Days or More</title>
      <link>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2571371#M1000693</link>
      <description>&lt;P&gt;Fixed with the following example, it seems that by retrieved time somehow reverted back to D HH:MM:SS format but now works as expected:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get length of time ticket has been open in days, hours, minutes, seconds
var diff2 = GlideDateTime.subtract(new GlideDateTime(gr.sys_created_on), new GlideDateTime());
var timeOpenMS = diff2.getDurationValue();
// Runs when a ticket is viewed from the service protal &amp;gt; my tickets &amp;gt; incident
gs.info("The duration of this ticket is: " + diff2.getDurationValue()); //syslog_list.do&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example conditions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set escalation widget to false by default
if (timeOpenMS &amp;lt; "04:00:00" &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp; gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp;
            (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
            data.showWidget = false;
            data.showEscalate = false;
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt; if (timeOpenMS &amp;gt; "5 00:00:00" &amp;amp;&amp;amp; data.table == 'incident' &amp;amp;&amp;amp; gr.active == true &amp;amp;&amp;amp;
                (gr.priority == 1 || gr.priority == 2 || gr.priority == 3 || gr.priority == 4) &amp;amp;&amp;amp;
                (gr.incident_state == 1 || gr.incident_state == 2) &amp;amp;&amp;amp; gr.escalation == 0 &amp;amp;&amp;amp;
                gr.company == 'ad0459981b7c0c100375ca217e4bcbb0' &amp;amp;&amp;amp;
                (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))) {
                data.showWidget = true;
                data.showEscalate = true;
                vEscalate = 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 12:59:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/issue-parsing-getdurationvalue-equalling-5-days-or-more/m-p/2571371#M1000693</guid>
      <dc:creator>Wasdom_Kung</dc:creator>
      <dc:date>2023-05-25T12:59:37Z</dc:date>
    </item>
  </channel>
</rss>

