- 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 05:44 AM
So it means that BR is not auto triggering
Until you manually save the form it means the resolved field is not getting populated whenever case is getting resolved
Did you check that?
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 05:49 AM
Hi Ankur,
The resolved field gets populated, which auto-triggers the Business Rule (BR) and updates the field in the backend as expected but without saving it. To save the value in the field (Business Duration To Resolve), it requires a manual save. This doesn’t make sense to me since this is a before BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 05:56 AM
Ideally the BR is before update so it should work
try this
(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);
// Set the duration to the custom field
current.u_business_duration_to_resolve = duration;
}
})(current, previous);
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:17 AM
Same issue, and no other business rules are clashing with this one. For me, It seems a timing issue where the saving happens before the field gets updated.