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

Ankur Bawiskar
Tera Patron
Tera Patron

@Ayaka KAZAMA 

you cannot access current object inside query business rule

try this

(function executeRule(current, previous /*null when async*/) { 
    var QueryString1 = 'short_descriptionNOT LIKE <specific name>^ORshort_descriptionISEMPTY'; 
    current.addQuery(QueryString1).addQuery('caller_id', '!=', 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

I tried with your script and I see an error. Do you know how to fix the error?

 

com.glide.script.RhinoEcmaError: Cannot convert null to an object.
sys_script.d8b2cc4cc32e1210dd5c9b477a0131c0.script : Line(3) column(0)
1: (function executeRule(current, previous /*null when async*/ ) {

2: var QueryString1 = 'short_descriptionNOT LIKE<specific name>^ORshort_descriptionISEMPTY';

==> 3: current.addQuery(QueryString1).addQuery('caller_id', '!=', gs.getUserID());

4:

5: })(current, previous);

 

And in addition to caller condition, I want to add watch list condition.

@Ayaka KAZAMA 

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

I don't see warning level log anymore but still the script doesn't work properly.

I'm not quite sure if this error is related to this Business rule but I attatch the log.

 

Cannot invoke "com.glide.monitor.AbstractBucketCollector.getName()" because "ac" is null: java.lang.NullPointerException: Cannot invoke "com.glide.monitor.AbstractBucketCollector.getName()" because "ac" is null: com.glide.ui.monitor.BucketStats.write(BucketStats.java:31)
com.glide.ux.metrics.stats.ApplicationCollector.lambda$write$2(ApplicationCollector.java:52)
java.base/java.util.HashMap.forEach(HashMap.java:1421)
com.glide.ux.metrics.stats.ApplicationCollector.write(ApplicationCollector.java:49)
com.glide.ux.metrics.stats.ClientInteractionXmlStatsProvider.write(ClientInteractionXmlStatsProvider.java:28)
com.glide.sys.stats.Statistician.write(Statistician.java:48)
com.glide.sys.stats.Statistician.createDocument(Statistician.java:101)
com.glide.ui.XMLStats.toDocumentWithInclude(XMLStats.java:68)
com.glide.ui.XMLStats.stats(XMLStats.java:42)
com.glide.processors.XMLStatsProcessor.process0(XMLStatsProcessor.java:12)
com.glide.processors.AAdminProcessor.process(AAdminProcessor.java:21)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:759)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:313)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58)
com.glide.sys.Transaction.run(Transaction.java:2734)
com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:35)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.lang.Thread.run(Thread.java:840)