Make all variables read only on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 03:39 AM
I want to make variables read only on a catalog item through onload script when certain conditions are met. Tried the options in
but could not get it working. Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 04:23 AM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 04:26 AM
I can use the UI policy but there are 75 variables so wanted to see if there is any script that can do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 04:51 AM
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,
☆ Community Rising Star 22, 23 & 24 ☆