<?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: Show Hours Only in Duration in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598090#M255016</link>
    <description>&lt;P&gt;There are currently no option/attribute of duration, which will display the duration in the form in which you need. I had the same requirement and wrote small function, which use DOM manipulations to hide unneeded input fields. To de mostly safe I initialized&amp;nbsp;&lt;STRONG&gt;doc&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;win&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;table&lt;/STRONG&gt; variables first of all by the following code:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var doc = g_form.getControl("someElementFromTheForm").ownerDocument,
	win = doc.defaultView,
	table = g_form.getTableName();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where&amp;nbsp;&lt;STRONG&gt;someElementFromTheForm&lt;/STRONG&gt; is the column name of some element of the form. The main code is the following:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var hideMinSecFields = function (field) {
		function getElem (field, suffix, prefix) {
			return doc.getElementById((prefix || "") + table + "." + field + (suffix || ""));
		}
		var controlHour = getElem(field, "dur_hour", "ni."),
			controlMin = getElem(field, "dur_min", "ni."),
			controlSec = getElem(field, "dur_sec", "ni."), cs;			

		if (controlMin != null &amp;amp;&amp;amp; controlMin.style != null) {
			controlMin.style.display = "none";
		}
		if (controlSec != null &amp;amp;&amp;amp; controlSec.style != null) {
			if (win != null &amp;amp;&amp;amp; win.getComputedStyle != null) {
				cs = win.getComputedStyle(controlSec, null);
				if (controlHour != null &amp;amp;&amp;amp; controlHour.style != null &amp;amp;&amp;amp; cs != null) {
					controlHour.style.borderRightStyle = cs.getPropertyValue("border-right-style");
					controlHour.style.borderRightWidth = cs.getPropertyValue("border-right-width");
					controlHour.style.borderRightColor = cs.getPropertyValue("border-right-color");
					controlHour.style.borderBottomRightRadius = cs.getPropertyValue("border-bottom-right-radius");
					controlHour.style.borderTopRightRadius = cs.getPropertyValue("border-top-right-radius");
				}
			}
			controlSec.style.display = "none";
		}
	};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To hide the min/sec fields you need just call &lt;STRONG&gt;hideMinSecFields&lt;/STRONG&gt; function with the name of the duration field as parameter.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Mar 2018 18:06:14 GMT</pubDate>
    <dc:creator>Oleg</dc:creator>
    <dc:date>2018-03-21T18:06:14Z</dc:date>
    <item>
      <title>Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598089#M255015</link>
      <description>&lt;P&gt;How can I see only hours? Either removing minutes and seconds fields OR having them disabled (read-only).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/191411i8EC0A842270DA2F3/image-size/large?v=v2&amp;amp;px=999" srcset="/community/image/serverpage/image-id/191411i8EC0A842270DA2F3/image-size/large?v=v2&amp;amp;px=999 1.0x" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 17:43:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598089#M255015</guid>
      <dc:creator>Beto</dc:creator>
      <dc:date>2018-03-21T17:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598090#M255016</link>
      <description>&lt;P&gt;There are currently no option/attribute of duration, which will display the duration in the form in which you need. I had the same requirement and wrote small function, which use DOM manipulations to hide unneeded input fields. To de mostly safe I initialized&amp;nbsp;&lt;STRONG&gt;doc&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;win&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;table&lt;/STRONG&gt; variables first of all by the following code:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var doc = g_form.getControl("someElementFromTheForm").ownerDocument,
	win = doc.defaultView,
	table = g_form.getTableName();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where&amp;nbsp;&lt;STRONG&gt;someElementFromTheForm&lt;/STRONG&gt; is the column name of some element of the form. The main code is the following:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var hideMinSecFields = function (field) {
		function getElem (field, suffix, prefix) {
			return doc.getElementById((prefix || "") + table + "." + field + (suffix || ""));
		}
		var controlHour = getElem(field, "dur_hour", "ni."),
			controlMin = getElem(field, "dur_min", "ni."),
			controlSec = getElem(field, "dur_sec", "ni."), cs;			

		if (controlMin != null &amp;amp;&amp;amp; controlMin.style != null) {
			controlMin.style.display = "none";
		}
		if (controlSec != null &amp;amp;&amp;amp; controlSec.style != null) {
			if (win != null &amp;amp;&amp;amp; win.getComputedStyle != null) {
				cs = win.getComputedStyle(controlSec, null);
				if (controlHour != null &amp;amp;&amp;amp; controlHour.style != null &amp;amp;&amp;amp; cs != null) {
					controlHour.style.borderRightStyle = cs.getPropertyValue("border-right-style");
					controlHour.style.borderRightWidth = cs.getPropertyValue("border-right-width");
					controlHour.style.borderRightColor = cs.getPropertyValue("border-right-color");
					controlHour.style.borderBottomRightRadius = cs.getPropertyValue("border-bottom-right-radius");
					controlHour.style.borderTopRightRadius = cs.getPropertyValue("border-top-right-radius");
				}
			}
			controlSec.style.display = "none";
		}
	};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To hide the min/sec fields you need just call &lt;STRONG&gt;hideMinSecFields&lt;/STRONG&gt; function with the name of the duration field as parameter.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 18:06:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598090#M255016</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-21T18:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598091#M255017</link>
      <description>&lt;P&gt;How do I run this? onLoad client script?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 22:41:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598091#M255017</guid>
      <dc:creator>Beto</dc:creator>
      <dc:date>2018-03-21T22:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598092#M255018</link>
      <description>&lt;P&gt;Yes of cause. It's a part of code, which will be start onLoad.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 04:22:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598092#M255018</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-22T04:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598093#M255019</link>
      <description>&lt;P&gt;Sorry, can you give me the steps? I'm not sure where and how to implement this.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 17:45:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598093#M255019</guid>
      <dc:creator>Beto</dc:creator>
      <dc:date>2018-03-22T17:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598094#M255020</link>
      <description>&lt;P&gt;You cannot use getControl with duration field.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 19:18:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598094#M255020</guid>
      <dc:creator>jayesh mohan2</dc:creator>
      <dc:date>2018-03-22T19:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598095#M255021</link>
      <description>&lt;P&gt;I'm not sure what you mean under "You cannot use getControl with duration field". Do you mean that it's not allowed? I posted fragment from the code of application, which is certified by ServiceNow and which is available on&amp;nbsp;https://store.servicenow.com/.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 21:57:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598095#M255021</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-22T21:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598096#M255022</link>
      <description>&lt;P&gt;I'm currently in business trip, but I'll try to post at the weekend more full example of the code or small demo application on GitHub, which uses the code, which I posted.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 22:01:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598096#M255022</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-22T22:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598097#M255023</link>
      <description>&lt;P&gt;Let us you have the table with some duration fields, for example,&amp;nbsp;&lt;STRONG&gt;field1&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;field2&lt;/STRONG&gt;. You can create Client Script with type &lt;STRONG&gt;onLoad&lt;/STRONG&gt;, which has the following code:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad() {
	var doc = g_form.getControl("field1").ownerDocument,
		win = doc.defaultView,
		table = g_form.getTableName(),
		hideMinSecFields = function (field) {
			function getElem (field, suffix, prefix) {
				return doc.getElementById((prefix || "") + table + "." + field + (suffix || ""));
			}
			var controlHour = getElem(field, "dur_hour", "ni."),
				controlMin = getElem(field, "dur_min", "ni."),
				controlSec = getElem(field, "dur_sec", "ni."), cs;			

			if (controlMin != null &amp;amp;&amp;amp; controlMin.style != null) {
				controlMin.style.display = "none";
			}
			if (controlSec != null &amp;amp;&amp;amp; controlSec.style != null) {
				if (win != null &amp;amp;&amp;amp; win.getComputedStyle != null) {
					cs = win.getComputedStyle(controlSec, null);
					if (controlHour != null &amp;amp;&amp;amp; controlHour.style != null &amp;amp;&amp;amp; cs != null) {
						controlHour.style.borderRightStyle = cs.getPropertyValue("border-right-style");
						controlHour.style.borderRightWidth = cs.getPropertyValue("border-right-width");
						controlHour.style.borderRightColor = cs.getPropertyValue("border-right-color");
						controlHour.style.borderBottomRightRadius = cs.getPropertyValue("border-bottom-right-radius");
						controlHour.style.borderTopRightRadius = cs.getPropertyValue("border-top-right-radius");
					}
				}
				controlSec.style.display = "none";
			}
		};
	hideMinSecFields("field1");
	hideMinSecFields("field2");
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's the same code, which I posted before, but where I&amp;nbsp;posted before. The controls in the form will be displayed without min/sec. Something like on the picture below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/191407iD97743B1BCC450B7/image-size/large?v=v2&amp;amp;px=999" srcset="/community/image/serverpage/image-id/191407iD97743B1BCC450B7/image-size/large?v=v2&amp;amp;px=999 1.0x" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 22:24:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598097#M255023</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-22T22:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598098#M255024</link>
      <description>&lt;P&gt;You can download a test application with one table and one form, which uses the script, from here: &lt;A href="https://github.com/OlegKi/Show-Hours-Only-in-Duration" rel="nofollow"&gt;https://github.com/OlegKi/Show-Hours-Only-in-Duration&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 12:04:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598098#M255024</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2018-03-24T12:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598099#M255025</link>
      <description>&lt;P&gt;Thanks everyone.&amp;nbsp; So there is no out-of-the-box solution other than high-level customization through the use of DOM manipulation which could be prone to errors during new releases?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 18:22:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/1598099#M255025</guid>
      <dc:creator>dmullinax</dc:creator>
      <dc:date>2022-08-30T18:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Show Hours Only in Duration</title>
      <link>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/2937488#M1115102</link>
      <description>&lt;P&gt;Was anyone able to hide the seconds field box on the portal?&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 00:19:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/show-hours-only-in-duration/m-p/2937488#M1115102</guid>
      <dc:creator>zynsn</dc:creator>
      <dc:date>2024-05-21T00:19:34Z</dc:date>
    </item>
  </channel>
</rss>

