Hide UI action for particular user

Sanket Kutwal
Tera Expert

Hello people, I'm trying hide UI policy for particular user, but the condition which i'm using is not working.

 

My requirement is to show this UI action to all the users who has admin role and plus it should also display to one particular user i.e 4f3e692c871e(sys_id), I tried below condition it's working fine it shows to all the admins and to all the users who are in that  in 'NOW - Records-IG' group, the problem is that is is visible to all the users who are in that group. i want to show only to this 4f3e692c871e particular user and to all users who has admin role.

 

Please let me know if you have any solution to solve this problem. 

 

Thank you!

 

image (5).png

 

3 ACCEPTED SOLUTIONS

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Sanket Kutwal 

 

You have to use below code in condition to show to particular user:

 

gs.getUserID()=='<sys_id of user>' along with other conditions.

 

If you don't want to show to group users can remove that part.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

manjusha_
Kilo Sage

@Sanket Kutwal 

The line  which you added in your ui action conditiion --gs.getUserID('4f3e692c871e')--this is not the correct condition

gs.getUserID() this method returns sys_id of the current logged in user

You just need to compare gs.getUserID() ==sys_id(the id of user whom you want show the ui action)

 

You can add condition as below

current.isValidRecord() && current.canDelete() && (gs.hasRole('admin') || gs.getUserID()=='4f3e692c871e')

 

4f3e692c871e This is sys_id of the user to which you wan to show your ui action

 

Mark this answer as correct and helpful if it helps

Thanks,

Manjusha Bangale

 

View solution in original post

@Sanket Kutwal 

Mark this answer as correct if it helped 

 

Thanks,

Manjusha Bangale

View solution in original post

9 REPLIES 9

manjusha_
Kilo Sage

@Sanket Kutwal 

The line  which you added in your ui action conditiion --gs.getUserID('4f3e692c871e')--this is not the correct condition

gs.getUserID() this method returns sys_id of the current logged in user

You just need to compare gs.getUserID() ==sys_id(the id of user whom you want show the ui action)

 

You can add condition as below

current.isValidRecord() && current.canDelete() && (gs.hasRole('admin') || gs.getUserID()=='4f3e692c871e')

 

4f3e692c871e This is sys_id of the user to which you wan to show your ui action

 

Mark this answer as correct and helpful if it helps

Thanks,

Manjusha Bangale

 

Thank you Manjusha, that was very well explained. This worked for me

Shamma Negi
Kilo Sage
Kilo Sage

With the AND condition you can write the below line in condition:

 

gs.getUserID() != ''62826bf03710200044e0bfc8bcbe5df1" //This is sample user sysid. put the sysid of the user you want to hide for

 

It checks if the current logged in user is equal to this userID. If not equal then it will give you true and show the UI Action if not equal then hide the UI action.

 

Hope it helps.

Regards,Shamma Negi

Thank you for your response, gotcha!

Samaksh Wani
Giga Sage
Giga Sage

Hello @Sanket Kutwal 

 

As per the new Community rules, You can mark multiple solution as Accept.

 

If you find my response as helpful, Please Mark it as Accepted.

 

Regards,

Samaksh