I want to make all fields read only of a table using client script but it has a lot of fields so it is very time consuming using g_form.setReadOnly().So is there any other way to do that?

Anish8
Kilo Contributor

I want to make all fields read only of a table using client script but it has a lot of fields so it is very time consuming using g_form.setReadOnly().So is there any other way to do that?

1 ACCEPTED SOLUTION

fkhan
Kilo Guru

Hi Anish,


Try this :



function onLoad() {


  var StrQry='';


  var fieldname = '';


  var gr = new GlideRecord('sys_dictionary');


  StrQry="name=incident";   //change the table name ,for example I used   'incident', and also you can add more query here.


  gr.encodedQuery = StrQry;


  gr.query();


  while(gr.next()){


  fieldname=gr.element;


  g_form.setReadOnly(fieldname,true);


  }


}



Thanks,


Farukh


View solution in original post

3 REPLIES 3

Deepak Kumar5
Kilo Sage

function onLoad(){


    try{


          //Get the 'Variables' section


          var ve = $('variable_map').up('table');


          //Disable all elements within with a class of 'cat_item_option'


          ve.select('.cat_item_option', '.slushselectmtm', '.questionsetreference', '.form-control', '.checkbox').each(function(elmt){


                elmt.disabled = true;


          });


          //Remove any reference or calendar icons


          ve.select('img[src*=reference_list.gifx]', 'img[src*=small_calendar.gifx]').each(function(img){


                img.hide();


          });


          //Hide list collector icons


          ve.select('img[src*=arrow]').each(function(img){


                img.up('table').hide();


          });


    }


    catch(e){}


}


Hi Deepak,


just FYI, if you recommend this script to someone, could you please also add that this will not be supported by ServiceNow Customer Support as we actively discourage our customers from using DOM manipulation? Please see ServiceNow KB: Date Variable values change when saving a record that includes the Variable Editor, i...   for more information.


fkhan
Kilo Guru

Hi Anish,


Try this :



function onLoad() {


  var StrQry='';


  var fieldname = '';


  var gr = new GlideRecord('sys_dictionary');


  StrQry="name=incident";   //change the table name ,for example I used   'incident', and also you can add more query here.


  gr.encodedQuery = StrQry;


  gr.query();


  while(gr.next()){


  fieldname=gr.element;


  g_form.setReadOnly(fieldname,true);


  }


}



Thanks,


Farukh