- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2022 10:41 AM
Is there a way to hide a variable based on the Catalog category selected in a variables set? I have a variable set which is populated to various forms which needs to hide a variable (reference field). I would like to hide the variable when Software category is selected. When I select "No" below, I get two reference fields. Is there a way to make the variable to be hidden if it is under Software category. Note, all these variables are under a variable set.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 07:35 AM
Hi
You can achieve this functionality by creating an onChange catalog client script on your variable set and a script include. It can run onchange your choice variable and then it should work as you want it.
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var sys_id = g_form.getUniqueValue();
var category = new GlideAjax('TestScriptInclude');
category.addParam('sysparm_name', 'getCatalogCategory');
category.addParam('sysparm_item', sys_id);
category.getXML(ResponseFunction);
function ResponseFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
g_form.setDisplay('reference field name',false);
} else {
// do what you want to do
}
}
}
Script include should be client callable.
var TestScriptInclude = Class.create();
TestScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCatalogCategory: function() {
var catalog = this.getParameter('sysparm_item');
var catItem = new GlideRecord('sc_cat_item');
catItem.addQuery('sys_id', catalog);
catItem.query();
if (catItem.next()) {
var cat = catItem.category;
}
if (cat == 'sys id of software category')
return true;
else
return false;
},
type: 'TestScriptInclude'
});
Please mark this as correct and helpful if it resolved the query or lead you in right direction.
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 08:44 AM
Thank you. It is helpfull.