Filter Configuration Item results in Change Request

log5212
Tera Contributor

Hello,

I have been having trouble for a little while now in attempting to filter results in the Change Request application for Configuration Items.

At first I attempted to do it via a Business Rule for Change Requests but at first it ended up not filtering the item at all when I set it up as a before ensuring it checks on any Updates or Queries. Then I changed it to be applied after Updates of Queries and I ended up filtering too much.

Here is my simplified business rule I attempted:
function filter_cis() {
var answer = ' ';
var includes = current.variables.textmatch;
var cis = new GlideRecord("ci_database");
cis.addQuery("name", "CONTAINS", includes);
cis.query();

while (cis.next()){
if (answer.length > 0 ){
if (cis.name != "3" || cis.name != "4" || cis.name != "5"){
answer += (',' + cis.name);
} }
else{
if (cis.name != "3" || cis.name != "4" || cis.name != "5") {
answer = cis.name;
} }}
return "nameIN" + answer;
}
I also attempted to replace the -- "nameIN" + answer; -- line and replaced it with -- "ci_fieldIN" + answer -- and that did not work. Just for kicks I also attempted to just -- return answer -- and that gave me no resolution as well.

Theoretically it should query the database and once it receives its result, it should filter out those items and return everything else. This did not seem to be the case.

Then I attempted to set it up as a Security Rule on Change Request. I selected to on any read record restrict access to any configuration items that were named after those 3 filter choices. However no configuration of read/write/create/edit or any other choice would ever stop those three results from appearing.

Have I accidentally over looked something or coded improperly?

I based my script off of the example provided here:
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers_for_Service_Catalog_Variables

I have also already read through:
http://wiki.servicenow.com/index.php?title=Using_Access_Control_Rules#Granting_or_Denying_Access

Attempting to follow those guides I have not been able to resolve my problem. Any help would be greatly appreciated.

The attached image is just another example of what I am trying to do.

4 REPLIES 4

benn23
ServiceNow Employee
ServiceNow Employee

Try cmdb_ci_database


log5212
Tera Contributor

I forgot to change that back, its just the very generic cmdb_ci.

I think I might have confused myself yesterday in my all day frustration. Ultimately I just want to make some CI's unavailable via the change request form but I do not think my business rule was really heading in the right direction. Might you have a resource for just not allowing some CI's in a Change Request benn23?

If I can get those CI's to be unavailable I wouldn't have to worry about a search result. I have experimented with Security Rules but I ended up just making my field unavailable. I also know if I'm not careful with my script it would also affect any other instance of the CI field across different applications on Service Now.


log5212
Tera Contributor

After taking a different approach to this problem I was able to in a semi quick fashion resolve it.

I ended up creating a global business rule that only ran when it was on a certain table. This allowed it to harmlessly run from the Reference Qualifier field in the Configuration Item > Dictionary.


function CI_filter() {
if (current.getTableName() == "change_request") {
return "{return your parameter which is set on the other CI's but configured differently on target CI's}";
}
}


log5212
Tera Contributor

edit: sanity repositioning comment