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 Question

Community Alums
Not applicable

Hi,

I have return a GlideAJAX and ScriptInclude but I am getting [Object Object]. Both the variables are DropDown variables (Protocol and Type) in the main table (u_cmdb_ci_file_share). Kindly help. 

 

GlideAJAX

GlideAJAX.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }


	var ga = new GlideAjax('ModifyNetworkSharePathClass');
	ga.addParam('sysparm_name', 'ModifyNetworkSharePathFunction');
	ga.addParam('passVariable', newValue);
	ga.getXML(callBackFunction);
	function callBackFunction(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		var op = JSON.parse(answer);
		g_form.setValue('share_type', op.sharetype);
		g_form.setValue('protocol_type', op.protocoltype);
	}


}

 

ScriptInclude

ScriptInclude.png

 

var ModifyNetworkSharePathClass = Class.create();
ModifyNetworkSharePathClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	ModifyNetworkSharePathFunction: function(){

		var valuesShare = this.getParameter('passVariable');
		var gr = new GlideRecord('u_cmdb_ci_file_share');
		gr.addQuery('sys_id', valuesShare);
		gr.query();
		if(gr.next()){
			var jsonOBJ = {};
			jsonOBJ.sharetype = gr.u_type;
			jsonOBJ.protocoltype = gr.u_protocol;
			var json = new JSON().encode(jsonOBJ);
			return json;
		}

	},

    type: 'ModifyNetworkSharePathClass'
});

 

output.png

 

type.pngprotocol.png

 

Regards

Suman P

 

1 ACCEPTED SOLUTION

Change it from getValue to getDisplayValue

 

Regards,

Sumanth

View solution in original post

8 REPLIES 8

SumanthDosapati
Mega Sage
Mega Sage

Hi @Community Alums 

Can you try JSON.stringify in script include instead of encode and try.

 

Regards,

Sumanth

Community Alums
Not applicable

Hi @SumanthDosapati,

 

I have changed it like this, still getting the same.

 

var ModifyNetworkSharePathClass = Class.create();
ModifyNetworkSharePathClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    ModifyNetworkSharePathFunction: function() {

        var valuesShare = this.getParameter('passVariable');
        var gr = new GlideRecord('u_cmdb_ci_file_share');
        gr.addQuery('sys_id', valuesShare);
        gr.query();
        if (gr.next()) {
            var jsonOBJ = {};
            jsonOBJ.sharetype = gr.u_type;
            jsonOBJ.protocoltype = gr.u_protocol;
          //  var json = new JSON().encode(jsonOBJ);
            return JSON.stringify(jsonOBJ);
        }

    },

    type: 'ModifyNetworkSharePathClass'
});

 

Regards

Suman P.

Community Alums
Not applicable

Hi @Runjay Patel,

 

Can you please help.

 

Regards

Suman P.

Hi @Community Alums ,

 

in client script use answer = answer.evalJSON(); instead of JSON.parse.

 

Also check this blog, it will help you for better understanding about GlideAjax: https://servicenowwithrunjay.com/return-multiple-values-to-glideajax-from-script-include/

 

Please accept the solution if it helped.