How to duplicate Businee Elapsed Time to Custom Field?

Kazuma Akita
Tera Contributor

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?

 

KazumaAkita_0-1718674846649.png

 

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage

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. 

DeepakShaerma_0-1718685899641.png

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 

View solution in original post

5 REPLIES 5

Deepak Shaerma
Kilo Sage

Hi @Kazuma Akita 
also make sure, your custom field type is also duration as same as SLA field.
Type ; Duration
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