- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 07:35 AM
Good day. Can anyone help me to display only the records created by the currently logged in user according to their user group using client script on load? My script
if(g_user.hasRole('x_886430_suggest.acn read only team')){
//I am now lost what I need to write but i am thinking
.setQuery("createdby=javascript:gs.getUserName();");
}else{
}
I am just new here at serviceNow.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 07:43 AM - edited 10-08-2022 07:47 AM
Try with before query Business Rule on your required table and in the script field of business rule try something like below.
(function executeRule(current, previous /*null when async*/ ) {
if (gs.getUser().isMemberOf('Group Name')) {
current.addQuery('sys_created_by', gs.getUser().getName());
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 09:55 AM
Hello,
Not sure I got your requirement but do you want to show the incidents which are created by a user and it is assigned to group he is a part of?
Please create a on before BR with the below script:-
(function executeRule(current, previous /*null when async*/ ) {
current.addEncodedQuery("assignment_groupIN" + gs.getUser().getMyGroups().toArray().join() + "^sys_created_by=" + gs.getUser().getName());
})(current, previous);
I see you have mentioned you cannot select the Query checkbox, is your advanced checbox selected as true
If it is selected then check the UI policy "Hide Advanced Controls" where the control is and see if it is correctly configured. Also you can configure dictionary of the query checkbox and see if it has been made readonly from the dictionary itself.
Please mark answer correct/helpful based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 10:11 AM
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 09:55 AM
Hello,
Not sure I got your requirement but do you want to show the incidents which are created by a user and it is assigned to group he is a part of?
Please create a on before BR with the below script:-
(function executeRule(current, previous /*null when async*/ ) {
current.addEncodedQuery("assignment_groupIN" + gs.getUser().getMyGroups().toArray().join() + "^sys_created_by=" + gs.getUser().getName());
})(current, previous);
I see you have mentioned you cannot select the Query checkbox, is your advanced checbox selected as true
If it is selected then check the UI policy "Hide Advanced Controls" where the control is and see if it is correctly configured. Also you can configure dictionary of the query checkbox and see if it has been made readonly from the dictionary itself.
Please mark answer correct/helpful based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 10:09 AM
Thank you for your help regarding to Query checkbox. I configured it now. I tried your script but still it did not show according to my requirements but I tried Muhammad Khan script and it work. You both help me. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 10:11 AM
You can mark both answer as correct if both helped you.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 10:16 AM
I see. Thank you