- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 10:45 AM
Good Afternoon Community,
I am trying to write a business rule that unchecks a checkbox on a form when the expire date is reached, ive tested it out so far and i have not gotten the expected results, in fact nothing is happening. Can anyone see what the problem is? Maybe my script needs adjusting?
Business rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gdt = new GlideDateTime().getDate();
var acl = new GlideRecord('u_cmdb_ci_table_access_parameters');
acl.addQuery("u_expire_date", "==", gdt);
acl.query();
if (current.u_expire_date.setDisplayValue() == gs.nowDateTime()) {
current.u_active = false;
}
})(current, previous);
Form with checkbox and expire date variable:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 09:13 PM
It would be helpful if you described what your actual requirements are instead of how you are trying to accomplish them. From what I gather, you want the "Active" checkbox to be unchecked once a certain date/time goes by, automatically, correct?
A Business Rule is probably not the best way to do that as it requires some kind of action in order for it to run. And a Before Query one is definitely not the way. They are normally used to alter a query/filter. (How business rules work).
A Workflow, as mentioned by someone else, makes more sense, but probably too expensive system-wise.
How many records are we talking about? How time-sensitive is this data? If not many and not very time-sensitive (i.e. does not have to happen immediately), a Scheduled Job may be your best bet. It can be scheduled to run every hour or so (or more frequently) to update the records.
The script could look like this:
(function() {
var gr = new GlideRecord("u_cmdb_ci_table_access_parameters");
gr.addEncodedQuery("u_active=true^u_expire_dateRELATIVELE@minute@ago@0");
gr.query();
while (gr.next()) {
gr.u_active = false;
gr.update();
}
})();
If it is time-sensitive, you could, in addition to the Scheduled Job, use a Before Display Business Rule to update the Active field when someone views the record in a form (will not affect when simply viewing records in a list view though):
And the Script field would be as simple as:
(function executeRule(current, previous /*null when async*/) {
current.u_active = false;
current.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 12:45 PM
How are you executing your script to test the records?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 01:44 PM
I am doing it via a business rule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 11:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 12:00 PM
Would i have to create a new workflow for this? This is a custom application i am working with.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 12:09 PM
Yes