Client script to make fields read only if user belongs to assignment group.

Balaram7
Kilo Sage

Hi all,

 

We have a requirement to make all fields read only on incident except State and Worknotes.

This should happen when user from the current assignment group opens the form.

if Assigned user is the current logged in user, then need to make state and worknotes only editable on the form. Remaining fields like contact type, email, category and sub category, ci, service needs to be read only.

Please help me with the client script to acheive this.

 

 

 

Thank you,

Balaram.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Balaram 

You can use client script for this

function onLoad(){

	if(g_user.userID == g_form.getValue('assigned_to')){
		// make all fields readonly
		var fields = g_form.getEditableFields();
		for (var x = 0; x < fields.length; x++) {
			g_form.setReadOnly(fields[x], true);
		}

		// make state and work notes editable
		g_form.setReadOnly('state', false);
		g_form.setReadOnly('work_notes', false);
	}
}

Regards
Ankur

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

View solution in original post

11 REPLIES 11

@Balaram 

Hope you are doing good.

Did my reply answer your question?

Would you mind closing the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

 

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

sachin_namjoshi
Kilo Patron
Kilo Patron

@Balaram Please mark my answer as correct if your issue is resolved.

 

Regards,

Sachin