- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 07:47 AM
Hi,
I am working on Before Query Business Rule.
I want to show the requested_for records to requested_for user who is logged in.
I have written the following code but its not working.I am only getting blank page.
Can u please look at it ?
(function ExecuteRule(current,previous)
{
if(gs.hasRole('myrole') && gs.getSession().isInteractive())
{
current.addQuery('requested_for','==',gs.getUserID());
}
})(current,previous);
I dont know why its not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 07:59 AM
Hello, please try as below (remove the '==')
(function ExecuteRule(current,previous){
if(gs.hasRole('myrole') && gs.getSession().isInteractive()){
current.addQuery('requested_for', gs.getUserID());
}
})(current,previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 08:35 AM
Hi there, glad to hear it is working now!
gs.hasRole will always return true if the user has the admin role...
As far as I am aware a 'hasRoleExactly' method does not exist server side...
Please check the answer on this post to create your own role checker (I have implemented the same and it works):
https://community.servicenow.com/community?id=community_question&sys_id=d8edab96dbd67f80d58ea345ca96195e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 08:36 AM
Modify the if condition of your previous business rule as below. No need for 2 business rules.
(function ExecuteRule(current,previous){
if((gs.hasRole('myrole') && !gs.hasRole('admin'))&& gs.getSession().isInteractive()){
current.addQuery('requested_for',gs.getUserID());
}
})(current,previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 08:39 AM