Make all variables read only on catalog item

samadam
Kilo Sage

I want to make variables read only on a catalog item through onload script when certain conditions are met. Tried the options in

https://community.servicenow.com/community?id=community_question&sys_id=ae4560e6dbe453c4852c7a9e0f96...

but could not get it working. Any ideas?

7 REPLIES 7

Priya Shid1
Kilo Guru

Hi samadhan,

use below code to make variables read only onSubmit of request,

function onSubmit() {

g_form.setVariablesReadOnly(true);
}

 

Please mark if that helps you!!

samadam
Kilo Sage

I can use the UI policy but there are 75 variables so wanted to see if there is any script that can do it.

Hi, 

Try to get all variables and set them as readOnly with this code, for client Script use

var allFields = g_form.getFieldNames(); and reuse for loop.

var gr = new GlideRecord('table'); 
if (gr.get('id')) { 
    var variables = gr.variables.getElements(); 
    for (var i=0;i<variables.length;i++) { 
        var question = variables[i].setReadOnly(true); 
        //g_form.setReadOnly(variables[i], true);for client script
    } 
}

If it was helpful, please give positive feedback.
Thanks, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆