Business Rule Troubleshooting

jamess_
Tera Contributor

I have a 3rd party Integration that writes to custom fields in Incident Management. I then have BRs that monitor those fields and make appropriate adjustments to the (native) Incident fields, based on our internal requirements. Most work very well.

One such rule, however, is set up to monitor the 3rd Party's "Status", and when they set to "Closed", we set our Incident to "Resolved". Is is configured to run After Update, and is the highest Order number for the Incident Table running After update.

I have a log message to verify the script is activating within seconds of the 3rd Party updating the monitored field, but the other fields I'm attempting to change with the BR are not updating.

If I use the same statements in a Background Script interactively, the Incidents update normally, although I do receive some alerts on other slow business rules). While I know how to turn on BR Debugging, it doesn't seem like I would receive any information from this because I'm not the one updating the Incident record. How do I catch whatever is going wrong when the BR attempts to set these field values (after the fact).

Business Rule Script:

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

gs.info('Business rule ********** started for Incident ' + current.number);

current.state = 6;
current.closed_at = current.u_custom_closed_date;
current.u_actual_resolution = current.u_custom_closed_date;
current.close_notes = 'Closed by Custom NOC';
current.u_major_system = 'Network';
current.u_category = 'Network System Issues';
})(current, previous);

1 ACCEPTED SOLUTION

The reason I asked this question is because, you will have to switch the BR to Before business rule. Changes made in before Business Rules are automatically saved when all before Business Rules are complete, and after Business Rules are best used for updating related, not current, objects

 

Thanks,

Pradeep Sharma

View solution in original post

11 REPLIES 11

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello James,

 

The business rule script you have shared is configured as After update? Is that right? If so then switch it to Before business rule and try once.

 

Thanks,

Pradeep Sharma

It is, but that's not exactly my question. Regardless of when it runs, how can I see the result of a particular line of script. One of them must be receiving an error, but I can only check periodically to see if the rule has run. In this case, my goal is to have the State field change to "Resolved", but because it is not, I assume the "current.state = 6;" statement is receiving an error. How do I find out what that error is?

Probably no errors, but because it is an "After" BR, you need to update the record with "current.update()".  That is why the fields are not updating for you.  A "Before" BR does not need the update statement (and in fact should NOT have one).

You might want to change it to a "Before" BR than runs at an order of 999.

One other thing - do you really want to set the "closed_at" field when it is only being set to "Resolved"?  Looks like you have the original closed date in the custom "u_custom_closed_date" field anyways.