Make assignment group and assigned to fields editable only to Admin and ITIL.

SBohare
Tera Contributor

The following is the Script I wrote for the above problem It doesn't seem to work. I want feed back. 

function onLoad(){
// condition to check roles of user
// other than users with roles ITIL
if( ! (g_user.hasRoleExactly("itil") || g_user.hasRoleExactly('admin') ) ){
// setting to readonly
g_form.setReadOnly('assignment_group',true);
g_form.setReadOnly('assigned_to',true);
}
}

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@SBohare 

why not use field level WRITE ACLs on those individual fields?

update script as this

function onLoad(){
	// condition to check roles of user
	// other than users with roles ITIL
	if(!g_user.hasRoleExactly("itil") && !g_user.hasRoleExactly('admin')){
		// setting to readonly
		g_form.setReadOnly('assignment_group',true);
		g_form.setReadOnly('assigned_to',true);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Shamma Negi
Kilo Sage
Kilo Sage

Try this field level ACL with script. It should work

ShammaSalhotra_1-1676975063688.png

 

 

Regards,Shamma Negi

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

SBohare
Tera Contributor

I went through the above query, and the answers there are neither complete nor working for me even after changing some parameters and adding more Scripts.Can you please look into the attachment and tell me if something looks fishy in there.

 

Community Alums
Not applicable

Hi @SBohare ,

 

You need to use the ACL for this.

Try to create write ACL for each field, so it will restrict editing from anywhere.

 

Anand

ServiceNow Developer

Ankur Bawiskar
Tera Patron
Tera Patron

@SBohare 

why not use field level WRITE ACLs on those individual fields?

update script as this

function onLoad(){
	// condition to check roles of user
	// other than users with roles ITIL
	if(!g_user.hasRoleExactly("itil") && !g_user.hasRoleExactly('admin')){
		// setting to readonly
		g_form.setReadOnly('assignment_group',true);
		g_form.setReadOnly('assigned_to',true);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader