Issue
Overview
You may have cases when you are trying to call business rule from schedule job to update some records but business rule is not updating correct records or not updating anything. This article will explain some ways to debug business rule in such cases.
Example
Lets take an example of 'Auto Cancel Change' scheduled job thats calling business rule, but somehow business rule is not getting the correct results or not updating the correct records.
1. First you need to make sure business rule script is getting triggered, to test this put some debug statements in your business rule.
-- For example here is your script you have for 'Auto Cancel Change' business rule:
var gr = new GlideRecord('change_request');
gr.addQuery('state', '-5');
gr.addQuery('approval', 'not yet requested');
var createddate = gr.addQuery('sys_created_on','>',gs.daysAgo(30));
gr.query();
var numrecord=gr.getRowCount();
gs.print("Number of Record Query is Getting :" + numrecord);
The value of approval 'not yet requested' is 'not requested' in choice list table. Make necessary change to query you are running and make sure you are getting some records now..
-- You can print more details to debug further details like 'gs.print(createddate);' to see if date you mentioned has the issues
Additional Information
1. Here please read more about Scripts - background module:
https://docs.servicenow.com/csh?topicname=c_ScriptsBackground.html&version=latest
Important Notes from above doc:
-- Administrators can use the Scripts - Background module to run arbitrary JavaScript code from the server.
-- Running free-form JavaScript can cause system disruption or data loss. ServiceNow does not recommend running free-from scripts from a production instance.
2. Here you can read more about Glide API's:
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GS-minutesAgo_N