- 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 11:30 AM
@SAI VENKATESH where in the client script is the variable visibility being set? Could you please advise. TY
- 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
}