The CreatorCon Call for Content is officially open! Get started here.

Make a field read-only unless it is a new record

jeremyeperdue
Giga Expert

Using the New Call Module as an example, is it possible to lock down a field as long as it is not new.

So on the New Call screen, we have a choice box called Call Type. Once the call record has been saved, or the user goes into the list of call records and drills into a saved call, I would like this field to be read only. I was thinking of setting the field to read only all the time and on new record setting read only to false. Is this possible?

1 ACCEPTED SOLUTION
4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Jeremy,



Please check for "isNewRecord()" in the below link.


http://wiki.servicenow.com/index.php?title=GlideForm_%28g_form%29





Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Here you go.


if(!g_form.isNewRecord()){ //if record is saved then make the field mandatory


  g_form.setMandatory('field_name', 'true');


}



Please mark the answer as correct if this answers your question.


Hi Pradeep,



Would this work for my incident state field.



I want to make the State read only on a new record, so that once its been submitted it can then be amended.



Would this script be correct?



  1. if(!g_form.isNewRecord()){ //if record is new state will be read only.
  2.   g_form.setReadOnly('state');  
  3. }


Would this be best applied as a Client Script?



Thanks,


Graham


Hi Graham,



Best Practice is to use UI Policy , Because too many client script on form increase loading of form. it can cause performance issue.


you can do this   by Client script too


You can achieve this using UI Policy   then create Ui policy actions like make state read only. you can use Conditions and script too.



pradeepksharma please correct me if I am wrong


find_real_file.png



Thanks & Regards


Govind Kumar Sharma