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

its triggering, but its putting the wrong value when the record is created in SOW. 
it works perfectly when i create the record using default view. 

 

 

@mcroxall 

did you see logs came till which line?

share the results

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

Shivalika
Mega Sage

Hello @mcroxall 

 

Get the url of the record and check if it contains "sysparm_view == sow" 

 

Include this above your whole script and it will trigger for sow as well. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

i am not sure i understand - this is the URL for a record created in SOW
https://xxxxxxxxxxx.service-now.com/now/sow/record/incident/6ae17dadfbbc621040e7f8d505efdc63/params/...

Hello @mcroxall 

 

You are giving me the link of record from "Service Operations Workspace" 

 

BR doesn't understands that, for it there is only VIEW. I am not sure if you have seen but we do have "Service Operations Workspace" as a "View". 

 

Additionally we also have "Service Operations Workspace New Record" - as a View for new records in SOW. 

 

So BR and all the things on server only recognize this. 

 

That's the reason, I told you to fetch the "record url" first, and then check if it contains "sysparm_view == 'sow') - in OOB that is the backend name of this view, then it will run. 

 

Hope this answers your queries.

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY