- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 08:38 AM
Hi Experts,
I have a requirement to show an error message when a ITIL user try to schedule a Change request, when exist a specific "Conflict" in Change Request.
I tried to resolve this with an onBefore Business Rule when the confict status is "Conflict" and the user have the ITIL role.
Here the Business Rule:
Condition: g_user.hasRole('itil')
var change = new GlideRecord('change_request');
change.addQuery('sys_id', current.change);
change.query();
var conflict = new GlideRecord('conflict');
conflict.addQuery('change',current.change);
conflict.query();
while (g.next()){
if (conflict.schedule == 'Fiscal Freeze'){
current.setAbortAction(true);
gs.addInfoMessage('No change allowed in fiscal freeze. Please alter the schedule.');
}
}
My Business Rule doesn't work and I don't know what I am missing.
I hope that you can help me.
Regards
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 01:10 PM
The key to business rules is understanding that they are triggered by database operations. If nothing has updated that conflict record, then running the business rule there isn't going to do any good.
Here's a thought... rather than an if, incorporate that in to the query. Your business rule should actually look like this (inside a function)
Name: Check for conflict
When: Before
Insert: true
Update: true
Condition: Conflict status | is | Conflict
(function executeRule(current, previous /*null when async*/) {
var conflict = new GlideRecord('conflict');
conflict.addQuery('change', current.sys_id);
conflict.addQuery('schedule.name', 'Fiscal Freeze 2017');
conflict.query();
if (conflict.next()) {
gs.addErrorMessage('No change allowed in fiscal freeze. Please alter the schedule');
current.setAbortAction(true);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 02:44 PM
The business rule has a condition to only run when the user has itil role in the condition field above the script.
gs.hasRole('itil')
If you think it is running at the wrong time (or not running at the right time), go to System Diagnostics> Debug Business Rules, click it, and test again. The transcript of which BRs are run and skipped is on the form at the bottom.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2021 06:49 AM
Hi Chuck. I was looking for a way to prevent creation/submission of a new change request if a conflict (blackout schedule) was detected and I came across this thread.
I set up the new BR as you have described, but it doesn't work the way I was expecting.
When a change request is new (with a conflict) and is submitted, I can see the business rule executes, but it doesn't stop the submission/creation of the change request.
If, after creation, i open the same change request and make a simple change then click Update, the BR executes again but this time I see expected behavior - i get error message at top and I stay on the change request form.
It seems like the BR works when changes are made to existing change requests, but not on the submission of a new change request.
Please see attached doc for screenshots of BR and my testing.
Thanks for any help you can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 11:13 PM - edited ‎10-10-2024 11:13 PM
@jammer did you get the solution for your requirement?
I'm also having the same requirement and facing same issue.
If you got the solution, Could you please provide that to me?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2024 04:57 AM
We ended up with an onSubmit client script that calls a script include to evaluate if dates are within a blackout period.
Here is the onSubmit code...