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

DPrasna
Tera Contributor

@Anne Marie Duff @Daniel Draes @Ian Leu 

Can you please help me with the above request

Danish Bhairag2
Tera Sage

Hi @DPrasna ,

 

Have u made the UI type as "All" for the above client script. ?

 

Thanks,

Danish

 

Yes I have and I tried to add a callback func for getreference however it didn't work either

Hi @DPrasna ,

 

Possible to share the snip of the error from console log?

 

Thanks,

Danish