Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

getEditableFields() is not working for reference field.

rajesh151
Mega Contributor

Hi,

getEditableFields() is not working for reference field.

Kindly help if I missing anything or I have to add anything.

Regards

Rajesh

3 REPLIES 3

rajesh151
Mega Contributor

One thing to add, all are mandatory.


How can I make all mandatory field for all table also read only through client script and on load.


Madhava_Kumar
Mega Guru

Hi Rajesh,



Even I got the same problem.



I solved the problem with the below code, you will get all the fields which are editable and reference as well.




g_form.elements.forEach(function (e, i) {


g_form.setMandatory(e.fieldName, false);


g_form.setReadOnly(e.fieldName, true);


});



thanks


Madhava


Venkateswarlu K
Mega Guru

Hi rajesh can u pls try this script


For ur requirement its working fine in my instance am currently using the Istanbul release



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }


              var f=g_form.getEditableFields();


              for(var x=0;x<f.length;x++){


                      g_form.setReadOnly(f[x],true);


                      alert('all fields are read only');


              }



}