Add an hour to time field in incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
i am trying to add an extra hour in time in time field but i face some problem .
this is my code running on before update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
(function executeRule(current, previous /*null when async*/) {
// Ensure the field has a value before proceeding
if (current.u_customtime) {
// Create a GlideDateTime object from the field's value
var gdt = new GlideDateTime(current.u_customtime.toString());
// Add one hour (3600 seconds)
gdt.addSeconds(3600);
// Set the value of the field directly from the modified GlideDateTime object
current.u_customtime = gdt;
}
})(current, previous);
Try this.
Abhishek Lawaniyan
=========================================================
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action will support the community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sagarpundir,
try something like this:
(function executeRule(current, previous /*null when async*/) {
var customTime = new GlideDateTime(current.u_customtime);
var newTime = customTime.addSeconds(300);
current.setValue('u_customtime', newTime);
})(current, previous);
let me know if that helped
/* 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
3 weeks ago
Try below in before business rule
(function executeRule(current, previous /*null when async*/) {
// Convert time field to a GlideDateTime object
var dt = new GlideDateTime(current.u_customtime);
// Add 1 hour = 3600 seconds
dt.addSeconds(3600);
// Retrieve only the time portion
var newTime = dt.getLocalTime().toString();
current.setValue('u_customtime', newTime);
})(current, previous);
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sagarpundir
Here’s how you can correctly add 1 hour to your time field:
(function executeRule(current, previous /*null when async*/) {
// Get the current time from the field
var gt = new GlideTime();
gt.setValue(current.u_customtime);
// Add 1 hour (3600 seconds)
gt.addSeconds(3600);
// Set back the updated value
current.setValue('u_customtime', gt.getValue());
})(current, previous);