Business duration left on Incident form

Abishek1998
Tera Contributor

Hi all,

 

I have created a new field named as business time left and Wrote a business rule on incident table to query the related task sla record and copy the same value and gets pasted there. now the field is not populated. I am pasting my script below.

My requirement is when the business time left  in task sla changes, The field on the incident form should also reflect same.

It is an ASYNC business rule.

(function executeRule(current, previous) {

    var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', current.sys_id);
    //slaGR.addQuery('active', true);
    slaGR.addQuery('sla.target', 'resolution');
    slaGR.setLimit(1);
    slaGR.query();

    if (slaGR.next()) {
        current.u_business_time_left = slaGR.getValue('business_time_left');
        current.update();
    }

})(current, previous);
2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Abishek1998 

you should have after update BR on task_sla with condition as Business time left Changes

(function executeRule(current, previous /*null when async*/ ) {

    // Ensure we are only targeting incidents
    if (current.task.sys_class_name == 'incident') {
        var incidentGR = new GlideRecord('incident');
        if (incidentGR.get(current.task)) {
            // Copy the business time left value from task_sla to the incident
            incidentGR.u_business_time_left.setDateNumericValue(current.business_time_left.dateNumericValue());
            incidentGR.update();
        }
    }

})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Tera Patron

Hi @Abishek1998 

 

What type of Field  business time left is? 

 

In this line  parse the value properly , it will be set .

current.u_business_time_left = slaGR.getValue('business_time_left');

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti