extend business rule condition statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 12:00 PM - edited ‎07-26-2023 12:07 PM
I am trying to extend business rule condition statement with script include. I tried the following but it does not work. Can you help?
I am doing this because I have more groups to include to add to the BR which would not fit in the condition statement field. The business rule is a query to run before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 06:46 PM
Hello @gracjan
I missed this point, as it is query business rule, it runs before the actual records are fetched you can not use current object in the condition field, as no objects will be available at the time of evaluation of this condition.
You can refer the official documentation here https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0956037
Accept my solution and mark it helpful if it helped you to resolve your query.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 01:19 PM - edited ‎07-27-2023 03:15 PM
Ok. So there is no way to use business rule to run the Before query BR to restrict visibility of Incidents with category Cybersecurity to only certain groups?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 06:00 PM
We can do that, If you requirement is to Restrict the category "Cyber Security" to only Specified group members,
1. Check for group membership of user in the Condition field, you can use a ScriptInclude if you feel like you have many groups to allow. Like the one below,
Script Include:
Name: CyberSecUtils
var CyberSecUtils =Class.create();
CyberSecUtils.prototype={
initialize :function(){},
cyberAllowedGroupMember :function(){
var currentUser = gs.getUser();
if(currentUser.isMemberOf(Â'Allowed Group A') || currentUser.isMemberOf(Â'Allowed Group B') || currentUser.isMemberOf(Â'Allowed Group C')){
return false;
}
return true;
},
type :'CyberSecUtils'};
Note: You can handle this logic however you want, like if there are 10 groups who are allowed to view the incident, putting them all in the if condition may not look good. In that case you can store all allowed groups in an array and iterate through array to check whether the user is part of any group or not, for example.
cyberAllowedGroupMember :function(){
var allowed_groups = ['Group A', 'Group B, 'Group C'];
for(var i=0; i < allowed_groups.length; i++){
if(currentUser.isMemberOf(Âallowed_groups[I])){
return false;
}
}
return true;
}
BR Condition Field:
new CyberSecUtils().cyberAllowedGroupMember()
2. Handle the category in query (in BR script). Like the one below,
(function executeRule(current, previous /*null when async*/ ) {
var cat = current.addNullQuery('category').addOrCondition('category','!=','Cyber Security');
})(current, previous);
Try like this.
Anvesh