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.

Why this Business Rule Script not working fro me?

1dusjhyahnt
Tera Contributor
(function executeRule(current, previous /*null when async*/) {

// Add your code here

current.addEncodedQuery('sys_created_onNOTONLastyear@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

})(current, previous);
10 REPLIES 10

Danish Bhairag2
Tera Sage

Hi @1dusjhyahnt ,

 

What is the filter that you want to apply?

 

Thanks,

Danish

 

hii @Danish Bhairag2 @Ankur Bawiskar 

 

means last year incident shown for non admin user , when it's opening incident form 

 

Condition :- !(gs.hasRole('admin'))

 

Script:- 

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here

current.addEncodedQuery('sys_created_onNOTONLastyear@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

})(current, previous);

Try this, I hope you are writing query business rule.

(function executeRule(current, previous /*null when async*/) {

// Add your code here

current.addEncodedQuery('sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

})(current, previous);
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi @1dusjhyahnt ,

 

What is the business requirement exactly. Why do u want to show tickets created in Last Year Only for non admin users? Because writing a BR will restrict the visibility globally & not only on LIST view.

 

But still if u want to proceed see below steps:

Please make sure u have a query Business rule for this & under condition field in advanced u can provide 

!(gs.hasRole('admin'))

 

& in the script section u can paste below code

current.addEncodedQuery('sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

 

Thanks,

Danish

 

Musab Rasheed
Tera Sage

Try this, I hope you are writing query business rule.

(function executeRule(current, previous /*null when async*/) {

// Add your code here

current.addEncodedQuery('sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');

})(current, previous);

 

Please hit like and mark my response as correct if that helps
Regards,
Musab