how to disable the field when a form is opened in view mode

Alextia
Giga Expert

I am just started working on service now, just wanted to disable the field when a form is opened in edit mode. is there any way to get it done?

 

Thanks

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Alextia 

can you share screenshots for the same i.e. in which mode are you referring?

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

@Ankur Bawiskar 

Sorry, since i am new to this, i might not be able to explain it with right term. If you could see the attached picture, you could understand what i meant by edit scenario. 

 

 

Alextia_0-1677049432631.png

 

@Alextia 

when you click New button it's an insert and when you open the record it's the existing record

you can differentiate this using onLoad client script and use g_form.isNewRecord() function

This will help you determine if it's a new record or an existing record

function onLoad(){
	if(!g_form.isNewRecord())
		g_form.setReadOnly('fieldName', 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

Its worked. Thanks a lot