The CreatorCon Call for Content is officially open! Get started here.

extend business rule condition statement

gracjan
Tera Guru

I am trying to extend business rule condition statement with script include. I tried the following but it does not work. Can you help?

scriphc.JPG

business rule.JPG

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.

7 REPLIES 7

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.

 

 

Thanks,
Anvesh

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?

@gracjan 

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.

 

Thanks,
Anvesh