How to make name value pair field read only ?

Shreya Nagar
Tera Contributor

ShreyaNagar_0-1697615209924.png

Hi , 

I have tried onChange client script when field value is changed then name value pair field will be read only but after form has been submitted then field will be non read only , I have also tried UI Policy and Dictionary but it also not working , Please let me know .

10 REPLIES 10

Sorry I didn't follow you.

namevalue pair field will be readonly but after form has been saved then field will be non read only . ???

Can you explain again when the field has to be editable and when will it be non editable?

-Anurag

once form has been saved field should be non editable 

You can try something like this

 

 if (!g_form.isNewRecord()) {
        g_form.setReadOnly('field name', true);
    }

 

This basically checks if it is a new record, will only make it read only if it is not a new record

 

-Anurag

Ankur Bawiskar
Tera Patron
Tera Patron

@Shreya Nagar 

you are saying

once form has been saved field should be non editable  -> so it means user should not edit on existing record

What happens when it's new record? It should be allowed for editing

you can use onLoad client script and determine if it's new record or not

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

I have tried above code but when form has been saved then name value pair field will be editable , As per my requirement after form has been saved then name value pair field should be read only .