- 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
04-15-2022 12:44 PM
Hi,
You can use UI policy to achieve this.
First create a UI policy and give your conditions in the When to Apply field.
Once you create the UI Policy, Create a new UI Policy action in the Related Lists. Here you can specify the field that you want to hide and select visible to be False.
Please refer below doc for better understanding
Please mark my response as correct answer or helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 06:14 AM
Catalog Categories do not come up as variables that we can set the condition on via UI policy action. I can only set condition on variables that are on the form.
- 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
04-27-2022 07:34 AM
Hi
Did you get a chance to look into my solution?
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)