- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 05:37 AM
Hi everyone,
I’ve configured a business rule to calculate the duration between case creation and resolution. However, the “business duration to resolve” field remains empty after the case is resolved until I manually save the form. Does anyone have suggestions on how to fix this issue?
(function executeRule(current, previous /*null when async*/ ) {
calculateBusinessDuration();
function calculateBusinessDuration() {
var createTime = current.sys_created_on.getGlideObject();
var resolveTime = current.resolved_at.getGlideObject();
// Define the schedule
var schedule = new GlideSchedule('1036f8e21b09c110779c6283b24bcb37');
// Calculate the duration considering the business hours
var duration = schedule.duration(createTime, resolveTime);
// Convert the duration to a GlideDuration object
var glideDuration = new GlideDuration(duration.getNumericValue());
// Set the duration to the custom field
current.u_business_duration_to_resolve.setValue(glideDuration.getValue());
}
})(current, previous);
Regards,
Mo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 06:35 AM
can you try to use after update BR and then use current.update() just after setting the field value
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 06:35 AM
can you try to use after update BR and then use current.update() just after setting the field value
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 07:18 AM
That works, thanks @Ankur Bawiskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 05:58 AM
I hope there is no other BR which is stopping the above BR to set the value?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader