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

I need business rule to make read only role specific?

Community Alums
Not applicable

Is there a way I can make a field read only to specific roles?

So for example everyone with ITIL it will show as read only but overridden by admin? 

Thanks

Andrew

5 REPLIES 5

Raju Koyagura
Tera Guru

If you want to make field read-only based on role either you can use UI Policy or Client Script but not sure why you are looking for a Business Rule? Is there any specific reason?

If you want to apply the role based condition in client script use g_user.hasRole("role_name").

https://docs.servicenow.com/bundle/jakarta-application-development/page/app-store/dev_portal/API_ref...

Community Alums
Not applicable

Hi, I don't necessarily want a business rule it was a generalization as I don't know how I go about it.

you can use hasRole() / hasRoles()

 

eg:

if(!gs.hasRole('admin'){

//code

}

 

If you need to set a field to read only you'll need to use a client script so you'll have to use GlideAjax to call a script include and run the query there.

Community Alums
Not applicable

David Dubuis,

Thanks again for helping out, at this rate I'm going to be skint buying you all these pints especially in London.

I need some further help... I'm not entirely sure how I should write it.

So the script needs to be something like,


if(gs.hasRole('ITIL')==true){g_form.setReadOnly (u_approved_hours, true)};

{

I'm still learning but getting there.. in short I need it to translate to,

If role is ITIL field readonly, field name is u_approved_hours

 

Thanks