Duration / Downtime field type advice and how duration fields works in terms of UI policies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 04:17 AM
Hi guys, on our CHG form we currently ask a yes/no question if there is to be 'Downtime?' - we want to change this so rather than asking yes/no, we ask 'Duration of downtime'?
What is the best way (field type) to force consistency of answers. Ideally we'd like them to specify in quarter/hundred intervals so 01.25 would be 1hr 15mins.
Logically I guess the 'Duration' field type makes most sense but I'm not familiar with this and when trying it am struggling to get a UI policy to work so that e.g. if the Downtime duration is anything other than 00:00:00:00 or >0 another field 'Downtime details' shows?
Any advice much appreciated. Thanks,
DS
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 06:16 AM
Indeed, the duration type field is the one intended for this purpose.
I add two fields: "Planned duration" and "Actual duration". I put them in the Schedule tab right under Planned start and end, and Actual start and end (respectively), then I make them auto-calculate based on these two fields.
I like to add the attribute "max_unit=hours" so that it shows as only hours and minutes and does not show the "days" field.
As for making "Downtime details" visible, when using a duration field you can actually just use the condition builder, and since its a duration field the operator that you use is actually "is greater than" and you just leave at zero and it works exactly like that.
The only missing part now is to make auto-populate it, usually making it a Calculated field, but this would not happen on the form. So it would render your UI Policy useless, so you actually would have to make Client Scripts to update the duration fields on both, start and end, field changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 08:29 AM
Hi, many thanks for you post. We actually want to add another duration field to our CHG schedule tab too! To use it to calculate the Planned end (date/time) field by adding the Duration value to the Planned start (date/time) field. Could you elaborate on how you have achieved this via 'auto-calculate' please? I had posted to the thread below earlier but so far have not had any replies:
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
I tried the greater than operator in the condition builder of the UI Policy but I could not get this other field showing/hiding as expected using this. I will double check using just the default values in the duration field i.e. 00:00:00.
Finally, changing the attribute makes sense but I don't see one called 'Max unit'. When I go to 'Add' an Attribute I am asked for Attribute which is a reference field (which I cannot see Max unit or anything pertaining to 'unit' listed) and then Value which is just a string so any further help setting this would be much appreciated.
Thanks again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 09:31 AM
Ah sorry, I missed that, then yes, you want to add Downtime start, Downtime end and Downtime duration.
To configure your Duration field right click on the field and select "Configure dictionary", this will bring up the system entry for that field, you will need to select the Advanced view for both of the following:
A) To calculate in the field definition set "Calculated=true" and on Calculation type something like this (adjust based on your field names):
(function calculatedFieldValue(current) {
// Add your code here
var plan_dur = new GlideDateTime();
plan_dur = gs.dateDiff(current.start_date.getDisplayValue(), current.end_date.getDisplayValue(), false );
return plan_dur; // return the calculated value
})(current);
B) To use only hours/minutes/seconds, go to the Attributes field and type in: max_unit=hours
C) To set the UI Policy, this is how I did it:
D) To set the duration on the form you would need to create a couple "onChange" Client Scripts to trigger off the Start and End fields, to run something similar like the script above, but for client side field get and put g_form commands.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2018 06:01 AM
Any idea on this issue... now we have actually decided to leave Days as part of the Duration field (!), we are seeing an issue with the 'Mandatory' field behaviour. That is with the 'Duration' field made mandatory the asterisk marking the field as mandatory is only going when a Day value is entered, i.e. if you enter hours, minutes or seconds it still remains.
Ideally we also need to account for when someone confirms there is no downtime by retyping 00:00:00:00 i.e. this should also make the mandatory asterisk go (as long as one of the value boxes has been selected and typed into with '00').
We are seeing the same problem on a simple UI policy i.e. a field that should show if the Duration is equal to or greater than 00:00:00:01 is only actually appearing when 1 day or more is entered?
Any ideas? Thanks!