Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Control variable visibility based on the selected Location's type (reference to cmn_location)

Dale Bersane
Tera Contributor

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.

2 ACCEPTED SOLUTIONS

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Dale Bersane 

 

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

View solution in original post

Hi @Dale Bersane 

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
   
}

View solution in original post

6 REPLIES 6

@SAI VENKATESH where in the client script is the variable visibility being set?  Could you please advise.  TY

Hi @Dale Bersane 

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
   
}