- 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 10:37 AM
I already change the code and it does not work.
Is there another way to do it?, I was thinking to do it with an UI Policy or what is the best practice to resolve it?
I appreciate your answers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 12:41 PM
A UI policy is going to run on the client side and won't tell you if there is a related record on the other table.
Can you share with me the details of the current business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 01:04 PM

- 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:30 PM
I did a test and it works, but I realize that If I do the test whatever the role be, the user can not change the planned start/end schedue and with an other role that is not ITIL, the message still showing.