- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 12:40 PM
I have a user who wants a yes or no field hidden at certain times on a servuce catalog request item. Between 8 am and 5 pm the field should be hidden. I know I need to use an onload client script for this, but I can't seem to find the code to make it work. Any suggestions are appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 12:45 PM
function onLoad() {
// Get the current time
var now = new Date();
var currentHour = now.getHours(); // returns 0-23
// Define the field name you want to show/hide
var fieldName = 'u_custom_field'; // Replace with your actual field name
// Hide the field between 8 AM and 5 PM (inclusive of 8, exclusive of 17)
if (currentHour >= 8 && currentHour < 17) {
gForm.setDisplay(fieldName, false);
} else {
gForm.setDisplay(fieldName, true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 12:45 PM
function onLoad() {
// Get the current time
var now = new Date();
var currentHour = now.getHours(); // returns 0-23
// Define the field name you want to show/hide
var fieldName = 'u_custom_field'; // Replace with your actual field name
// Hide the field between 8 AM and 5 PM (inclusive of 8, exclusive of 17)
if (currentHour >= 8 && currentHour < 17) {
gForm.setDisplay(fieldName, false);
} else {
gForm.setDisplay(fieldName, true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 01:05 PM - edited 07-31-2025 01:06 PM
@BrianProvencher it looks good 👍
@SusanSchwar just check on your global property whether your instance is 12 or 24 format and pray for being it 24 😄 as it would be easier to achieve..
EDIT: correction prey > pray
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 05:25 AM
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 05:24 AM
Thank you, this was helpful. Ultimately, I needed a server-side script included in my client script to get the time. Here is the script for anyone this may help.