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

I am unsure how to add logging.

The group name is spelled the same. 

I am unsure how to add logging for the business rule.

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

@Balaram 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

@Balaram 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

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