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.

Script Include and On change Client script using JS methods browser issue

DPrasna
Tera Contributor

Hi All,

 

I have a script include that returns the following result exactly as shown below with comma

 

"Development , Production"

Client Script (not working on Portal)

 

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		g_form.setVisible('column1',false);
		g_form.setVisible('column2',false);
		g_form.setVisible('column3',false);
		
		return;
	}	

	var prod = g_form.getReference('product');
	//alert(JSON.stringify(prod));
	//alert(prod.u_application_name);

	var ga = new GlideAjax('<scriptincludename>');
	ga.addParam("sysparm_name", "getCI");
	ga.addParam("sysparm_app_name", prod.u_application_name);
	ga.addParam("sysparm_sysid", newValue);
	//alert(newValue);
	//alert(newValue.getDisplayValue());
	ga.getXML(getResponse);

	function getResponse(response) {
		var res = response.responseXML.documentElement.getAttribute("answer");
		alert(res.toString());		
		
		//var res1 = res.toString();
		if(res.includes('Development')){	
			g_form.setVisible('column1',true);
			g_form.setVisible('column2',true);
			
		}
		if(res.includes('Production')){		
			g_form.setVisible('column2',true);
			g_form.setVisible('column3',true);
			
		}

	}

}

 

"

 

Now I need to have a client script to check the matches of the above returned results which is Dev/ Prod. I have the below script which works on Native UI but not on the Portal. It displays an error "There is a JavaScript error in your browser console 

I need help to make it compatible and make it work on the Portal as expected.

 

@Danish Bhairag2 @Sandeep Rajput @Ankur Bawiskar @Peter Bodelier @Chuck Tomasi 

 

 

11 REPLIES 11

Vishal Birajdar
Giga Sage

Hi @DPrasna 

 

Can you comment out below line of code in your script and check if you are getting alert.

 

if(res.includes('Development')){	
			g_form.setVisible('column1',true);
			g_form.setVisible('column2',true);
			
		}
		if(res.includes('Production')){		
			g_form.setVisible('column2',true);
			g_form.setVisible('column3',true);
			
		}

Not sure but issue might be  because of res.includes().... 

Just for debugging you can check..

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi Vishal, I tried however it doesn't show the alert even if I commented out the above lines