Display only the records created by the currently logged in user

Ni_a Sy
Tera Contributor

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.

2 ACCEPTED SOLUTIONS

Muhammad Khan
Mega Sage
Mega Sage

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);

 

View solution in original post

Saurav11
Kilo Patron
Kilo Patron

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

 

Saurav11_0-1665247946846.png

 

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.

View solution in original post

9 REPLIES 9

Ni_a Sy
Tera Contributor

Thank you.

Saurav11
Kilo Patron
Kilo Patron

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

 

Saurav11_0-1665247946846.png

 

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.

Ni_a Sy
Tera Contributor

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.

You can mark both answer as correct if both helped you.

 

Thanks

Ni_a Sy
Tera Contributor

I see. Thank you