Display UI action button based on role

chanikya
Kilo Sage

Here we have "Republish " button, it should be visible only   ---who are having " kb_retire" role     OR     who are the author in KB article.                                                                                                                                                             My condition is not working.....

if you see below image i am not a Author of this article and i don't have kb_retire   role, but it is visible me

it should be visible only=-------who are having " kb_retire" role         OR             who are the author in KB article.  

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

can you try now




gs.getUser().getRoles().indexOf('kb_retire') >= 0 || current.author==gs.getUserID() ||   !(gs.getUser().getRoles().indexOf('admin') >= 0 )  


View solution in original post

32 REPLIES 32

gs.getUser().getRoles().indexOf('kb_retire') >= 0 || current.author==gs.getUserID() ||   !(gs.hasRole('admin'))




Admin is super user. He satisfies all the roles in the system.try with hasRoleExactly() for admin


kindly refer the blog below.



https://joshneri.us/serverside-hasroleexactly-in-servicenow/


Hi,




can you plesae help me in my PDI


Dev28601


raj/ 1234


Harsh Vardhan
Giga Patron

try this gs.getUser().getRoles().indexOf('ur role name') >= 0 instead of g_user condition


still it is KB record is showing to admin's



&& (gs.hasRole('kb_retire') || current.author==gs.getUserID() ) && gs.getUser().getRoles().indexOf('admin') >= 0 )


can you try now




gs.getUser().getRoles().indexOf('kb_retire') >= 0 || current.author==gs.getUserID() ||   !(gs.getUser().getRoles().indexOf('admin') >= 0 )