
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-09-2020 03:38 AM
Here i'm going to share one script using that all variables in catalog item becomes read only.
Now we see that for making multiple field Read only we need to write one or more UI Policy action in case of ui policy as per the best practice and also it can be done using client script. But for that we need to write multiple g_form.setReadOnly() method of g_form API. Instead of doing this if you have a use case like set all variable ReadOnly ,Visible , mandatory so that time this will be useful.
So just create one variable of type checkbox in catalog item and write OnChange() client script for that variable and call Server side Script include by making client callable is tick.
Before CheckBox is Tick
After the Checkbox is Tick Check result
OnChange() Client script on Checkbox variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sys_id_record = g_form.getUniqueValue(); //it will return record sys_id
if (newValue == 'true')
{
var ga = new GlideAjax('global.Test');//Call script include Test
ga.addParam('sysparm_name', 'getDetails');//getDetails is function name
ga.addParam('sysparm_rec_sys_id', sys_id_record);
ga.getXML(Callback);
function Callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var res = answer.split("-");
var res1 = answer.split(",");
//alert(res[1]);
alert("Variable Count(res) ="+res);
alert("Variable name" =+res1);
for (var i = 0; i <= res[1]; i++)
{
g_form.setReadOnly(res1[i], "true");//here set all variable read only
}
}//function close
}//if close
else //if checkbox is untick then all field becomes unRead
{
var ga = new GlideAjax('global.Test');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('sysparm_rec_sys_id', sys_id_record);
ga.getXML(Callback);
function Callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var res = answer.split("-");
var res1 = answer.split(",");
alert("Variable Count(res) ="+res);
alert("Variable name(res1)" =+res1);
for (var i = 0; i <= res[1]; i++)
{
g_form.setReadOnly(res1[i], "false");//here set all variable unread
}
}//function close
}//else close
}
Script include
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var count="";
var arr = [];
//var sysid = this.getParameter('sysparm_rec_sys_id');//get record sys_id
// gs.addInfoMessage("sysid=" + sysid);
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', this.getParameter('sysparm_rec_sys_id'));
gr.query();
while (gr.next()) {
gs.addInfoMessage("Catalog Item Name= "+gr.name);
var gr_variable = new GlideRecord('item_option_new'); //Glide variable table
gr_variable.addQuery('cat_item.name', gr.name);
gr_variable.query();
while (gr_variable.next()) {
arr.push(gr_variable.name.toString()); //pass the variable name into array (arr)
count=gr_variable.getRowCount(); // get the count of vaiable
} //while close
}
return arr.toString()+"-"+count; //return array contains varaible name with variable count
},
type: 'Test'
});
One more thing if you have use case like Make Visible and Mandatory then only one change in client script that change method g_form.setReadOnly() to g_form.setVisible() and g_form.setMandatory().
Mark Helpful this Article and Bookmark if it help you in any way.
- 848 Views