The CreatorCon Call for Content is officially open! Get started here.

UI policy Script to show/hide related list based on user roles

Michael Galang
Tera Contributor

Hi Experts, 

 

Good day! 

I just want to ask your expert opinion on how to control show/hide of related list using UI policy. 

I created  UI policy that should control the show/hide of Related List name (task_sla.task) using below conditions and 

MichaelGalang_0-1711503781396.png

 

with the g_user that will check the user role based on below specific roles 

MichaelGalang_1-1711503965780.png

 
However, when I impersonate a user that doesn't have the required roles the realated list (task_sla.task) still showing. 

I would appreciate any help help regarding this matter. 

Thanks in advance.  



1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @Michael Galang you dont need to pass sysid under hasRole. You need to use like below

Refer documentation: https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/client/c_GlideUserAPI#r_GlideUs...

var isItil = g_user.hasRole('itil');

 

Regards
Harish

View solution in original post

5 REPLIES 5

Prerna_T
Tera Contributor

Hello @Michael Galang 
Instead of using Else conditions you can use g_form.hideRelatedList for a specific role that the user has. 

 

 

function onCondition() {
var testInc = g_user.hasRole('itil');
if (testInc)
{
g_form.hideRelatedList('task_sla');
}

}
 
If you want to make double sure you can use ElseIf condition, but I believe the above example will help. 

Please hit Helpful if it helps