Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Need to update Incident field based on sla business percentage

Bijender
Tera Guru

Hi,
I need to update incident field when incident resolves check the SLA business percentage , if less than 100% update the field with yes else no.

Tried creating a before update business rule on incident table  but not working

(function executeRule(current, previous /*null when async*/) {
    var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', current.sys_id); 
    slaGR.addQuery('sla.name', 'P3 resolution'); // Match SLA name
    slaGR.query();
    if (slaGR.next()) {
           if (slaGR.business_percentage < 100) {
            current.u_sla_cal = 'Yes';
        } else {
            current.u_sla_cal = 'No';
        }  
    }
})(current, previous);


Regards,
B

5 REPLIES 5

Shree_G
Mega Sage

@Bijender ,

 

Use below format to set value :

 

current.setValue('u_sla_cal','Yes');

current.update();

 

no still not working,  tried to log the SLA name to see if its picking up the sla, but the logs shows undefined

 

Hello @Bijender ,

 

The script is working fine. Check the business rule conditions. try setting up when "State" changes to Resolve.

 

Tried in the Background scripts and working fine.

Shree_G_0-1745924174696.png

Output

Shree_G_1-1745924193598.png

 

J Siva
Kilo Patron

Hi @Bijender 

Try the below script.

(function executeRule(current, previous /*null when async*/ ) {
    var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', current.sys_id);
    slaGR.addEncodedQuery('business_percentage<100^sla.name=P3 resolution'); // CHANGE THE SLA NAME AS REQUIRED
    slaGR.query();
    if (slaGR.next()) {
        current.u_sla_cal = 'Yes';
    } else {
        current.u_sla_cal = 'No';
    }

})(current, previous);

Regards,
Siva