- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 09:15 AM - edited 05-31-2024 10:22 AM
I am building a catalog item and I need to control the visibility of the form variable "A" based on the selection of variable "B". NOTE: variable "B" is a reference to the cmn_location table. The tricky part is that I need to dot walk to a custom column on the location table to get the appropriate condition.
Goal: Show variable "A" only if variable "B" has a type of "C".
Example: Show the "Desk Number" variable on the catalog form if the "Location" selected (on the form) has a type designated as "Desk"(custom reference column on the location table that is referencing another table).
Any help would be greatly appreciated. Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 10:38 AM
You can try the below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestedFor = g_form.getValue('prefered_location');
alert(requestedFor);
var ga = new GlideAjax('GetManagerDetailsScript');//script include name
ga.addParam('sysparm_name', 'getlocation'); // function name used in script include
ga.addParam('sysparm_requested', requestedFor);
ga.getXMLAnswer(callback);
function callback(response){
var answer=response;
alert(answer);
}
//Type appropriate comment here, and begin script below
}
script include:
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getlocation: function(){
var requestedFor = this.getParameter('sysparm_requested');
var grcountry = new GlideRecord('cmn_location');
grcountry.addQuery('sys_id', requestedFor);
grcountry.query();
if (grcountry.next()) {
return grcountry.country;
}
},
});
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 11:50 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestedFor = g_form.getValue('prefered_location');
alert(requestedFor);
var ga = new GlideAjax('GetManagerDetailsScript');//script include name
ga.addParam('sysparm_name', 'getlocation'); // function name used in script include
ga.addParam('sysparm_requested', requestedFor);
ga.getXMLAnswer(callback);
function callback(response){
var answer=response;
if(answer=="USA"){
g_form.setVisble('prefered_location',true);
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 09:42 AM
Hi @Dale Bersane ,
You can achieve this by creating onChange catalog client script for the variable B. Copy paste the below code and do the mentioned changes.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var locationValue = g_form.getReference('variable B', LocationInfo);
function LocationInfo(locationValue) {
if (locationValue.type == "C") {
g_form.setReadOnly('Variable A', true); //Control visibility
} else {
g_form.setReadOnly('Variable A ', false); //Control visibility
}
}
}
Please let me know if you've any questions.
Please mark the answer helpful, if it helped you accordingly.
Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 10:15 AM
@Hari Prasath Thank you for writing this up, unfortunately this does not work. It is not setting the visibility for anything i select in the location variable. (NOTE: i changed the control visibilitiy lines form setReadOnly to setDisplay).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 10:28 AM
Hi @Dale Bersane ,
Please use below script
var locVal = g_form.getReference('location_variable', getRefLocation);
function getRefLocation(locVal) {
if (locVal.type.includes(variable_a)) {
g_form.setDisplay('Variable_a', true); //Show
} else {
g_form.setDisplay('Variable_a', false); //Hide
}
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 10:38 AM
You can try the below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestedFor = g_form.getValue('prefered_location');
alert(requestedFor);
var ga = new GlideAjax('GetManagerDetailsScript');//script include name
ga.addParam('sysparm_name', 'getlocation'); // function name used in script include
ga.addParam('sysparm_requested', requestedFor);
ga.getXMLAnswer(callback);
function callback(response){
var answer=response;
alert(answer);
}
//Type appropriate comment here, and begin script below
}
script include:
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getlocation: function(){
var requestedFor = this.getParameter('sysparm_requested');
var grcountry = new GlideRecord('cmn_location');
grcountry.addQuery('sys_id', requestedFor);
grcountry.query();
if (grcountry.next()) {
return grcountry.country;
}
},
});
Thanks and Regards
Sai Venkatesh