Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

特定の条件に当てはまる場合のIncidentテーブルの閲覧を制御したい

Ayaka KAZAMA
Giga Guru

(English follows Japanese)

 

Incidentテーブルの閲覧を制限するBusiness Ruleを作っています。

① systemユーザーではない
② インタラクティブユーザーである
③ 特定のグループのメンバーではない
④ Callerではない
⑤ Watch listに入っていない

 

このすべての条件が満たされる場合に、「Short descriptionが「特定の名称」ではない、あるいは、空白である」Incidentが見れるようにしたいです。

 

①~③の条件はConditionで記載できたのですが、④~⑤がうまくいきません。

Condition:

gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<特定のグループのsys_id>')==-1

 

Script:

 

(function executeRule(current, previous /*null when async*/ ) {
    var QueryString1 = 'short_descriptionNOT LIKE特定の名称^ORshort_descriptionISEMPTY';
    current.addQuery(QueryString1);
	
})(current, previous);

 

 

Condition を以下に書き換えてもうまくいきません。
gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<特定のグループのsys_id>')==-1 && current.caller_id != gs.getUserID() && current.watch_list.indexOf(gs.getUserID()) == -1

 

どうしたら実現できるか、ご存知の方はいらっしゃいますか?

 

---

I am creating a Business Rule to restrict access to the Incident table.

  1. The user is not a system user.
  2. The user is an interactive user.
  3. The user is not a member of a specific group.
  4. The user is not the Caller.
  5. The user is not on the Watch list.

If all these conditions are met, I want users to be able to view Incidents where the “Short description” is not a “specific name” or is empty.

I was able to specify conditions for 1 to 3, but I’m having trouble with 4 and 5.

 

Condition:

gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<specific group sys_id>') == -1

 

Script:

 

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addQuery(QueryString1); 
})(current, previous);

 

 

Even when I rewrite the condition as follows, it doesn’t work:

gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<specific group sys_id>') == -1 && current.caller_id != gs.getUserID() && current.watch_list.indexOf(gs.getUserID()) == -1

 

Does anyone know how I can achieve this?

19件の返信19

I tried with this.

 

When to run: before

 

Query: true

 

Condition: gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<specific group sys_id>') == -1

 

Script: 

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addEncodedQuery(QueryString1).addQuery('caller_id', '!=', gs.getUserID()).addQuery('watch_listNOT LIKE' + gs.getUserID()); 
})(current, previous);

@Ayaka KAZAMA 

did you try to debug by removing conditions in script 1 by 1?

Also remember there are OOB table.None READ ACLs on incident table which you will have to update with similar conditions.

try this

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addEncodedQuery(QueryString1); 
})(current, previous);

then try this

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addEncodedQuery(QueryString1).addQuery('caller_id', '!=', gs.getUserID())); 
})(current, previous);

then try this

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addEncodedQuery(QueryString1).addQuery('caller_id', '!=', gs.getUserID()).addQuery('watch_listNOT LIKE' + gs.getUserID()); 
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rajesh Chopade1
Mega Sage

hi @Ayaka KAZAMA 

 

try bellow script once in your BR:

(function executeRule(current, previous /*null when async*/) {
    // Check if the user is an interactive user, not a system user, and not in the specified group
    if (gs.getUserName() != 'system' && gs.isInteractive() == true && gs.getUser().getMyGroups().indexOf('<specific group sys_id>') == -1) {
        
        // Check if the user is not the caller and is not on the watch list
        if (current.caller_id != gs.getUserID() && current.watch_list.indexOf(gs.getUserID()) == -1) {
            
            // Exclude incidents where the short description is a specific name or is empty
            var query = 'short_description!=<specific name>^ORshort_descriptionISEMPTY';
            current.addQuery(query);
        }
    }
})(current, previous);

 

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh

One quick question, if I use your script, should I clear "condition" section?

Yes, we handle all in script.