
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2018 10:43 AM
How can I see only hours? Either removing minutes and seconds fields OR having them disabled (read-only).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 03:24 PM
Let us you have the table with some duration fields, for example, field1 and field2. You can create Client Script with type onLoad, which has the following code:
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 && controlMin.style != null) {
controlMin.style.display = "none";
}
if (controlSec != null && controlSec.style != null) {
if (win != null && win.getComputedStyle != null) {
cs = win.getComputedStyle(controlSec, null);
if (controlHour != null && controlHour.style != null && 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");
}
It's the same code, which I posted before, but where I posted before. The controls in the form will be displayed without min/sec. Something like on the picture below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 03:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 03:24 PM
Let us you have the table with some duration fields, for example, field1 and field2. You can create Client Script with type onLoad, which has the following code:
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 && controlMin.style != null) {
controlMin.style.display = "none";
}
if (controlSec != null && controlSec.style != null) {
if (win != null && win.getComputedStyle != null) {
cs = win.getComputedStyle(controlSec, null);
if (controlHour != null && controlHour.style != null && 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");
}
It's the same code, which I posted before, but where I posted before. The controls in the form will be displayed without min/sec. Something like on the picture below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2018 05:04 AM
You can download a test application with one table and one form, which uses the script, from here: https://github.com/OlegKi/Show-Hours-Only-in-Duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 12:18 PM
You cannot use getControl with duration field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 02:57 PM
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 https://store.servicenow.com/.