- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 06:41 PM
Hi community.
Does anyone have any insight on how to use a business rule to get the Business Elapsed Time value and store it in a custom field, Test Elapsed Time?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 09:45 PM
Hi @Kazuma Akita
Business rule will run on Before or After you insert or update the Incident record. if you want to copy the business elapsed time in your custom field. then it will only update when u do some changes on the form.
When to Run: After - Insert/Update both
Table : Incident
(function executeRule(current, previous /*null when async*/ ) {
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task', current.sys_id);
taskSlaGR.addQuery('stage', 'in_progress'); // Ensuring it’s the in-progress SLA
taskSlaGR.query();
// Check if an in-progress SLA is found
if (taskSlaGR.next()) {
// Get the business duration (elapsed time) from the SLA in milliseconds
var businessDurationMs = taskSlaGR.business_duration;
// Ensure businessDurationMs is not null or undefined
if (!businessDurationMs) {
gs.log("No business duration found for task " + current.sys_id);
return;
}
// Store the exact duration in milliseconds in the custom duration field
current.u_test_elapsed_time.setValue(businessDurationMs);
} else {
gs.log("No in-progress SLA found for task " + current.sys_id);
}
current.update();
})(current, previous);
try this code in Business rule.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 09:45 PM
Hi @Kazuma Akita
Business rule will run on Before or After you insert or update the Incident record. if you want to copy the business elapsed time in your custom field. then it will only update when u do some changes on the form.
When to Run: After - Insert/Update both
Table : Incident
(function executeRule(current, previous /*null when async*/ ) {
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task', current.sys_id);
taskSlaGR.addQuery('stage', 'in_progress'); // Ensuring it’s the in-progress SLA
taskSlaGR.query();
// Check if an in-progress SLA is found
if (taskSlaGR.next()) {
// Get the business duration (elapsed time) from the SLA in milliseconds
var businessDurationMs = taskSlaGR.business_duration;
// Ensure businessDurationMs is not null or undefined
if (!businessDurationMs) {
gs.log("No business duration found for task " + current.sys_id);
return;
}
// Store the exact duration in milliseconds in the custom duration field
current.u_test_elapsed_time.setValue(businessDurationMs);
} else {
gs.log("No in-progress SLA found for task " + current.sys_id);
}
current.update();
})(current, previous);
try this code in Business rule.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 11:22 PM
Hi @Deepak Shaerma
Thank you for your response.
I tried to implement it as you suggested, but the values were not displayed in the custom fields. Is there any reason for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 05:14 AM
@Kazuma Akita
also make sure, your custom field type is also duration as same as SLA field.
Type ; Duration
check you correct backend name for the custom field and business elapsed field.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 01:31 AM
I was able to achieve the requirement with the following script based on what received. Thank you very much!
(function executeRule(current, previous /*null when async*/ ) {
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task', current.sys_id);
taskSlaGR.addQuery('stage', 'in_progress'); // Ensuring it’s the in-progress SLA
taskSlaGR.query();
// Check if an in-progress SLA is found
while (taskSlaGR.next()) {
// Get the business duration (elapsed time) from the SLA in milliseconds
var busElapsedTime = taskSlaGR.business_duration;
var busTimeLeft = taskSlaGR.business_time_left
// Ensure busElapsedTime is not null or undefined
if (!busElapsedTime && !busTimeLeft) {
gs.log("No business duration or business time left found for task " + current.sys_id);
return;
}
// Store the exact duration in milliseconds in the custom duration field
taskSlaGR.u_test_elapsed_time.setValue(busElapsedTime);
taskSlaGR.u_test_time_left.setValue(busTimeLeft);
taskSlaGR.update();
}
})(current, previous);