BR not triggering correctly in SOW

mcroxall
Tera Guru

 

I have created a BR to track our FCR in the incident table. The BR executes as expected on Default view, however when i create a incident record in the SOW it sets the wrong value. I can't figure it out why since all conditions are met. The field will correct update when the record goes from Resolved to closed, but from insert or update to Resolved it sets the value to "FCR not achieved" which should since the criteria are the same.

2025-04-08_22-56-18.png

Here its my script for the BR:

(function executeRule(current, previous) {

// Define state constants
var STATE_NEW = '1';
var STATE_IN_PROGRESS = '2';
var STATE_ON_HOLD = '3';
var STATE_RESOLVED = '6';
var STATE_CLOSED = '7';
var STATE_CANCELED = '8';

var state = current.getValue('state');

// Do not update FCR if state is New, In Progress, or Canceled
if (state == STATE_NEW || state == STATE_IN_PROGRESS || state == STATE_CANCELED) {
return;
}

var fcrValue = 'FCR Not Achieved';

var openedBy = current.getValue('opened_by');
var resolvedBy = current.getValue('resolved_by');
var assignedTo = current.getValue('assigned_to');
var reassignmentCount = parseInt(current.getValue('reassignment_count') || '0', 10);
var reopenCount = parseInt(current.getValue('reopen_count') || '0', 10);

var isFinalState = (state == STATE_RESOLVED || state == STATE_CLOSED);

// Check for On Hold history
var wasOnHold = false;
var auditGR = new GlideRecord('sys_audit');
auditGR.addQuery('documentkey', current.sys_id);
auditGR.addQuery('fieldname', 'state');
auditGR.addQuery('newvalue', STATE_ON_HOLD);
auditGR.setLimit(100);
auditGR.query();
if (auditGR.hasNext()) {
wasOnHold = true;
}

var isAssignedExternally = assignedTo && assignedTo != openedBy && assignedTo != resolvedBy;

if (
isFinalState &&
!wasOnHold &&
openedBy &&
resolvedBy &&
openedBy == resolvedBy &&
reassignmentCount === 0 &&
reopenCount === 0 &&
!isAssignedExternally
) {
fcrValue = 'FCR Achieved';
}

current.u_first_contact_resolution = fcrValue;

})(current, previous);

 

1 ACCEPTED SOLUTION

Vasantharajan N
Giga Sage
Giga Sage

@mcroxall - Please set the order for your business rule to 999 and check.

 

When the BR order is 100 then it is not setting the resolved by value when this BR is triggered from SOW.  Please check. 


Thanks & Regards,
Vasanth

View solution in original post

11 REPLIES 11

Vasantharajan N
Giga Sage
Giga Sage

@mcroxall - Please set the order for your business rule to 999 and check.

 

When the BR order is 100 then it is not setting the resolved by value when this BR is triggered from SOW.  Please check. 


Thanks & Regards,
Vasanth

this worked perfectly! should have thought about it! thank you!