Updating Catalog item variable on click in custom table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 08:57 AM - edited 04-19-2024 08:57 AM
Hello, I'd like to set the attribute of Catalog Item variable to ReadOnly by setting "Active" to false on my custom table. It looks like this:
This variable is reference. I tried to use UI Policy on this table with the script:
var variableField = g_form.getControl('u_variable');
var ga = new GlideAjax('CatalogItemUtils');
ga.addParam('sysparm_name', 'updateVariableReadonly');
ga.addParam('sysparm_variable', variableField);
ga.getXMLAnswer(function(response) {
});
And Script Include:
updateVariableReadonly: function(active) {
// Update the field properties based on the checkbox status
var ac= new GlideRecord('item_option_new');
ac.addQuery("sys_id",this.getParameter('sysparm_variable'));
ac.query();
if(ac.next()){
ac.setattribute('read_only', 'true');
//ac.setAttribute.read_only = true;
//ac.read_only = true;
ac.update();
}
},
It doesn't work 😞
How is it possible to achieve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 10:52 AM - edited 04-19-2024 10:53 AM
In you UI Policy try:
g_form.setReadOnly('<field_name>', true);
And change your script include to return true/false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 08:55 PM
Hi @MysUser ,
Try this script (few changes I did)-
Client Script
var variableSysId = 'your_variable_sys_id'; // Replace 'your_variable_sys_id' with the actual sys_id of your variable
var ga = new GlideAjax('CatalogItemUtils');
ga.addParam('sysparm_name', 'updateVariableReadonly');
ga.addParam('sysparm_variable', variableSysId); // Pass the variable sys_id
ga.getXMLAnswer(function(response) {
// Handle the response if needed
});
Script Include
var CatalogItemUtils = Class.create();
CatalogItemUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateVariableReadonly: function() {
var variableSysId = this.getParameter('sysparm_variable');
var ac = new GlideRecord('your_custom_table'); // Replace 'your_custom_table' with the actual table name
if (ac.get(variableSysId)) {
ac.setValue('read_only', true);
ac.update();
}
}
});
Please mark as Accepted Solution if this solves your query .