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

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-26-2025 03:35 AM
(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.
- The user is not a system user.
- The user is an interactive user.
- The user is not a member of a specific group.
- The user is not the Caller.
- 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?
- ラベル:
-
business rule
-
Incident

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-27-2025 02:03 AM
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);
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-27-2025 02:27 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-26-2025 10:35 PM
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

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-26-2025 10:54 PM
One quick question, if I use your script, should I clear "condition" section?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-26-2025 10:56 PM
Yes, we handle all in script.